Repository navigation
[BUG] StructuredOutput tool wraps data in 'output' field causing schema validation to fail #502
Description
Activity
Additional data point: The wrapper key can also be
"response"instead of"output":{ "response": { "actions": [...] } }Same error:
Output does not match required schema: root: must have required property 'actions', root: must NOT have additional propertiesAnother wrapper variant observed:
{"json": {...}}in addition to{"output": {...}}and{"response": {...}}.the same question
+1
- added a commit that references this issue
on Jan 29, 2026 +1
Reacted by Naren ManoharanYes, I am also facing this
Reacted by Niyas Hameed, Naren Manoharan, Mickaël, chi-dd, orr-adaptive and urielcosThis is so frustrating. We're now setting ourselves up for just asking for a natural language response from Claude and then using ChatGPT to coerce it into a proper structured response. This appears to be a much more robust strategy.
- marked StructuredOutput tool fails when agent wraps output in
{"output": {...}}#571 as a duplicate of this issueon Mar 24, 2026 - marked Structured outputs seems to be flaky #374 as a duplicate of this issue
on Mar 24, 2026 FWIW, the pre tool use hook strategy documented on #374 seems like a good approach as you can rewrite the JSON in that hook and unwrap (or correct as required) before running the structured output tool.
FWIW, the pre tool use hook strategy documented on #374 seems like a good approach as you can rewrite the JSON in that hook and unwrap (or correct as required) before running the structured output tool.
This is the solution we currently use, but it is still a bit flaky because once in a while we meet a new keyword we haven't accounted for (e.g we handle "output" and "result" but suddenly get "json")
FWIW, the pre tool use hook strategy documented on #374 seems like a good approach as you can rewrite the JSON in that hook and unwrap (or correct as required) before running the structured output tool.
+1, but so far has anyone else found another workaround worth exploring? Although I would think that the pre tool use hook is fairly decent at mitigating an issue like this.
The flakiness also seems to be showing when outputs get lengthier.
Any updates on progress in this regard? seems like such a basic concept that without it we can't really trust the library.
Reacted by Alexander Campbell and Thomas PortalI've been battling the unreliability of
ClaudeAgentOptions(output_format=...)for months (to the extent that we're now asking Claude Code for informal JSON responses and then give them to OpenAI ChatGPT to reliably produce structured output). Now I just had a confusing conversation with Claude in which it explained that theclient.messages.parse(output_format=...)argument (same asoutput_config.format) guarantees schema-constrained sampling butClaudeAgentOptions(output_format=...)employs a validate-retry loop, suggesting that it does not use schema-constrained sampling. And of course the entire existence of this issue (#502) indicates that schema-constrained sampling is not used. Can someone from Anthropic enlighten us whether schema-constrained sampling is indeed not used, and, if so, why not?(I wish I could share the conversation, but it's in a corporate claude.ai account and can't be shared publicly due to Claude's limitations.)
Unbelievable this hasn't been fixed. OpenAI's structured output has worked since day 1
+1
+1
@qing-ant can you please get this addressed? This is a major blocker to using the agent SDK in any real production system. This should have been the number 1 priority bugfix the day it was created.
Bug Description
When using structured outputs with
output_format, theStructuredOutputtool intermittently wraps user data in an{"output": {...}}field. Validation fails when the wrapper is present.This is non-deterministic - same prompt can produce either format:
Impact
ResultMessage.structured_outputisNonewhen wrapper is presentTool Response Error
This error confuses Claude because:
actionsis "required" but exists insideoutputadditionalProperties: false, sooutputis invalidClaude tried to "debug" by reducing output from 47 items to 1 item.
Environment
Related
properties/parameters)