Skip to content

fix(ai): 🐛 Drop response_format when the provider refuses json_object too - #163

Merged
vitofico merged 1 commit into
mainfrom
fix/ai-response-format-fallback
Oct 30, 2026
Merged

vitofico merged 1 commit into
mainfrom
fix/ai-response-format-fallback

Conversation

@vitofico

Copy link
Copy Markdown
Owner

Insights failed on Claude Haiku 5.5 right after #162: every request ended in a 400.

Anthropic's OpenAI-compatible endpoint accepts response_format only as strict json_schema, and it refuses BookInsightPayload under strict mode because the schema has a free-form map (additionalProperties: object). The client then fell back to {"type": "json_object"} as designed (#102), and Anthropic refuses that type outright ("response_format.type: Input should be 'json_schema'").

The fallback now has one more step. If json_object is refused the same way, the request goes without response_format, with the schema already in the prompt, and the client remembers that shape for later calls. Providers that accept json_schema or json_object behave exactly as before.

Checked live: two insight calls against claude-haiku-5-5 both validated against BookInsightPayload (13 s each). A new unit test replays Anthropic's two rejection messages verbatim.

@vitofico
vitofico merged commit 3f0721e into main Oct 30, 2026
8 checks passed
@vitofico
vitofico deleted the fix/ai-response-format-fallback branch October 30, 2026 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant