You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using gemini-3.5-flash (or any Gemini 3+ model) with both Structured Output (json_schema) and Google Search grounding (or url_context / code_execution) enabled simultaneously, the plugin raises:
PluginInvokeError: "Structured output (json_schema) cannot be used with: grounding, url_context"
This makes it impossible to get both grounded (web-searched) answers AND structured JSON output in a single LLM node — a common requirement for agentic workflows.
Root Cause
The plugin's _generate() calls the legacy generateContent endpoint (genai_client.models.generate_content()). A model-agnostic static validator _validate_feature_compatibility() hard-blocks json_schema whenever any other feature is active (Rule 1: "json_schema is exclusive").
This rule was correct for Gemini <=2.5 models, where the Google API genuinely rejects the combination:
400 INVALID_ARGUMENT: "controlled generation is not supported with google_search tool"
However, Gemini 3+ models support combining Structured Outputs with built-in tools natively — but only via the Interactions API (client.interactions.create()), which is GA since June 2026 and recommended by Google for all new development.
On the legacy generateContent endpoint, the combination silently de-grounds on GA Gemini 3 models (HTTP 200, but groundingMetadata is empty — model answers from parametric memory only, no error). See google-gemini/cookbook#1274 for a deterministic repro.
"Gemini 3 lets you combine Structured Outputs with built-in tools, including Grounding with Google Search, URL Context, Code Execution, File Search, and Function Calling."
Migration guide (migrate-to-interactions): all structured-output + tools examples use client.interactions.create(), not models.generate_content().
SDK: google-genai>=1.55.0 already supports the Interactions API (client.interactions.create()). The plugin's current google-genai dependency satisfies this.
Proposed Fix
Add a conditional Interactions API code path for Gemini 3+ models when json_schema + native tools are both active. Keep generateContent as the default for everything else (backward compatible).
1. Make _validate_feature_compatibility model-aware
@staticmethoddef_validate_feature_compatibility(
model_parameters: Mapping[str, Any],
tools: Optional[list[PromptMessageTool]] =None,
model: Optional[str] =None, # <-- NEW param
) ->dict[str, Any]:
# ... existing code ...# Rule 1: json_schema is mutually exclusive with all other features# Exception: Gemini 3+ models support combining json_schema with# native tools via the Interactions API.iffeatures["json_schema"] andlen(enabled_features) >1:
_has_native_tools=any(
adjusted_params.get(f)
forfin ["grounding", "url_context", "code_execution"]
)
ifmodelandmodel.startswith("gemini-3") and_has_native_toolsandnottools:
pass# Gemini 3+ with native tools -> Interactions API pathelse:
other_features= [fforfinenabled_featuresiff!="json_schema"]
raiseInvokeError(
f"Structured output (json_schema) cannot be used with: {', '.join(other_features)}"
)
input format: Must be Step dicts {"type": "user_input"/"model_output", "content": [...]}. Passing types.Content directly causes Unknown parameter 'parts' at 'input[0]'.
response_format: Must be a single dict, NOT a list. Passing both response_format (as list) + response_mime_type (as separate kwarg) causes responseFormat must be set when responseMimeType is set.
thinking_level: Must be lowercase "minimal"/"low"/"medium"/"high", NOT the uppercase enum values used by generateContent.
Streaming GC: Must keep _client_ref = genai_client in the stream handler to prevent garbage collection from closing the HTTP connection ([Errno 9] Bad file descriptor).
Dify version
1.14.2
Plugin version
gemini 0.9.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Create a Dify workflow with an LLM node
Select model gemini-3.5-flash
Enable Grounding (Google Search)
Enable Structured Output with any JSON schema
Run the workflow -> error: "Structured output (json_schema) cannot be used with: grounding"
✔️ Error log
PluginInvokeError: {"args":{"description":"[models] Error: Structured output (json_schema) cannot be used with: grounding, url_context"},"error_type":"InvokeError","message":"[models] Error: Structured output (json_schema) cannot be used with: grounding, url_context"}
Description
When using
gemini-3.5-flash(or any Gemini 3+ model) with both Structured Output (json_schema) and Google Search grounding (orurl_context/code_execution) enabled simultaneously, the plugin raises:This makes it impossible to get both grounded (web-searched) answers AND structured JSON output in a single LLM node — a common requirement for agentic workflows.
Root Cause
The plugin's
_generate()calls the legacygenerateContentendpoint (genai_client.models.generate_content()). A model-agnostic static validator_validate_feature_compatibility()hard-blocksjson_schemawhenever any other feature is active (Rule 1: "json_schema is exclusive").This rule was correct for Gemini <=2.5 models, where the Google API genuinely rejects the combination:
However, Gemini 3+ models support combining Structured Outputs with built-in tools natively — but only via the Interactions API (
client.interactions.create()), which is GA since June 2026 and recommended by Google for all new development.On the legacy
generateContentendpoint, the combination silently de-grounds on GA Gemini 3 models (HTTP 200, butgroundingMetadatais empty — model answers from parametric memory only, no error). See google-gemini/cookbook#1274 for a deterministic repro.Evidence
Google docs (structured-output, updated 2026-07-07):
Migration guide (migrate-to-interactions): all structured-output + tools examples use
client.interactions.create(), notmodels.generate_content().google_search grounding silently disabled when structured/JSON output is requested (gemini-3.5-flash) google-gemini/cookbook#1274 (Jun 22, 2026): deterministic silent de-grounding on
gemini-3.5-flashviagenerateContent— 0/5 grounded in JSON mode vs 5/5 in prose mode.[Feature Request] Support Google Search Grounding with Structured Outputs - Gemini 3 vercel/ai#11599 (closed) + #11815 (closed): combination works on preview models (
gemini-3-pro-preview,gemini-3-flash-preview) but not GA models via the legacy endpoint.SDK:
google-genai>=1.55.0already supports the Interactions API (client.interactions.create()). The plugin's currentgoogle-genaidependency satisfies this.Proposed Fix
Add a conditional Interactions API code path for Gemini 3+ models when
json_schema+ native tools are both active. KeepgenerateContentas the default for everything else (backward compatible).1. Make
_validate_feature_compatibilitymodel-aware2. Route to Interactions API in
_generate()3. New
_generate_via_interactions()4. New
_handle_interactions_response()5. New
_handle_interactions_stream_response()Key gotchas discovered during development
inputformat: Must be Step dicts{"type": "user_input"/"model_output", "content": [...]}. Passingtypes.Contentdirectly causesUnknown parameter 'parts' at 'input[0]'.response_format: Must be a single dict, NOT a list. Passing bothresponse_format(as list) +response_mime_type(as separate kwarg) causesresponseFormat must be set when responseMimeType is set.thinking_level: Must be lowercase"minimal"/"low"/"medium"/"high", NOT the uppercase enum values used bygenerateContent._client_ref = genai_clientin the stream handler to prevent garbage collection from closing the HTTP connection ([Errno 9] Bad file descriptor).Dify version
1.14.2
Plugin version
gemini 0.9.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
gemini-3.5-flash"Structured output (json_schema) cannot be used with: grounding"✔️ Error log