Skip to content

fix: unwrap StructuredOutput tool's spurious output envelope - #1184

Open
SushantTusharJoshi wants to merge 1 commit into
anthropics:mainfrom
SushantTusharJoshi:fix/structured-output-wrapping
Open

fix: unwrap StructuredOutput tool's spurious output envelope#1184
SushantTusharJoshi wants to merge 1 commit into
anthropics:mainfrom
SushantTusharJoshi:fix/structured-output-wrapping

Conversation

@SushantTusharJoshi

Copy link
Copy Markdown

Summary

  • Adds _unwrap_structured_output() helper in message_parser.py that strips the {"output": <data>} wrapper when present
  • Recovers structured data from result text when structured_output is None but JSON is embedded in the result string
  • Only unwraps single-key {"output": ...} dicts — multi-key dicts pass through safely

Test plan

  • 9 regression tests covering: normal passthrough, wrapped unwrapping, text recovery, multi-key preservation, scalar/list passthrough
  • All tests pass
  • Ruff lint clean

Closes #502

Developed with Claude Code as a coding partner

…ics#502)

The StructuredOutput tool non-deterministically wraps user data in an
extra {"output": <data>} envelope, causing schema validation to fail and
structured_output to be None on ResultMessage. Detect the single-key
wrapper during result parsing and strip it so callers always see the
schema-conformant payload.

Handles both cases: when the CLI returns the wrapped dict directly on
structured_output, and when validation fails and the wrapped JSON only
appears in the result text field.

Developed with Claude Code as a coding partner
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.

[BUG] StructuredOutput tool wraps data in 'output' field causing schema validation to fail

1 participant