Fall back to JSON object mode when model rejects json_schema#58
Open
DavertMik wants to merge 1 commit into
Open
Fall back to JSON object mode when model rejects json_schema#58DavertMik wants to merge 1 commit into
DavertMik wants to merge 1 commit into
Conversation
Models that don't support strict JSON Schema structured outputs (e.g. many Groq/OpenRouter models, especially reasoning models) failed every structured-output call with "This model does not support response format `json_schema`". Provider.generateObject now detects that error, marks the model, and retries in JSON object mode: output:'no-schema' (which sends response_format json_object), the schema injected into the prompt, and the reply validated against the original Zod schema. The model is remembered for the session so later calls skip the failed first attempt. Also forward agentName:'planner' from the planner so its per-agent providerOptions (e.g. reasoningEffort) actually apply — previously they were dropped, so a reasoning model could spend its whole output budget thinking and never emit the plan JSON. Suppress the AI SDK system-message-in-messages warning on provider calls. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Models that don't support strict JSON Schema structured outputs failed every structured-output call (test planning, supervisor verdicts, etc.) with:
The AI SDK's default
generateObjectstrategy always asks the provider forresponse_format: json_schema; providers like Groq (and many OpenRouter models, especially reasoning models) reject it for unsupported models, so the whole step failed and retried identically.Fix
Provider.generateObjectnow degrades gracefully:isJsonSchemaUnsupportedError) and remember the model for the session (so later calls skip the failed first attempt).output: 'no-schema'(which makes the provider sendresponse_format: { type: "json_object" }), the JSON Schema injected into the prompt, and the reply validated against the original Zod schema. This matches the provider's documented "JSON Object Mode".json_schemaerror as non-retryable, so it falls back immediately instead of burning retries.Also in this PR
[Planner]forwardsagentName: 'planner'togenerateObject. Previously the planner passed no options, somergeProviderOptionsdropped its per-agent config — meaningai.agents.planner.providerOptions(e.g.reasoningEffort) was silently ignored. This matters because a reasoning model with full reasoning can spend its entire output budget thinking and never emit the plan JSON; the fix lets users disable/tune reasoning for the planner.allowSystemInMessageswarning on provider calls (the codebase intentionally carries the system prompt as the first message).Which models this helps
The fallback is provider-agnostic — it triggers on the error string and works for any provider whose unsupported models still accept
json_object. From the live OpenRouter model list (340 models): 264 already supportjson_schema(never needed this), and 23 supportjson_objectbut notjson_schema— those now work. Examples:qwen/qwen3-235b-a22b,nousresearch/hermes-4-405b/70b,z-ai/glm-4.5,google/gemma-4-31b-it,ai21/jamba-large-1.7,microsoft/wizardlm-2-8x22b,nvidia/llama-3.3-nemotron-super-49b-v1.5. (53 models support neither and remain unsupported.)Verification
qwen/qwen3.6-27bthrough the realProvider: without the fix →Failed to validate JSON; with it → 4 scenarios returned.bun test tests/integration/→ 62/62 passbun run format/bun run lint:fixclean🤖 Generated with Claude Code