[BUG] `--json-schema` defined JSON doesn't exist in `structured_output`
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
I'm using claude code to run a custom slash command:
claude --dangerously-skip-permissions --output-format json --json-schema "$(cat ./schema.json)" --append-system-prompt "$(cat ./prompt.md)" -p "/my-command"
Based on the document the result json should include field structured_output with the json object defined by the schema. But what I got is a json without structured_output. Instead, the json includes field result which is a markdown string include the json object expected.
And unfortunately, sometimes the json in the markdown doesn't follow the definition in the schema. In my case, there is a field in the json expect the value is a number, which is extracted from a string. I guess this is because the prompt explains how to extract the data for the json.
One example what I got:
{
"type": "result",
//...
"result": "xxx\n```json\n{\n\"key\": \"value\"\n}\n```"
}
What Should Happen?
In the result json, the schema defined json object should exist in structured_output field. For example:
{
"type": "result",
//...
"structured_output": {
// the json content defined by the schema
}
}
Error Messages/Logs
Steps to Reproduce
- Define a json schema and a prompt to describe how to get the values required by the json schema
- Call claude with `-p --output-format json --json-schema $(cat ./schema.json) --append-system-prompt $(cat ./prompt.md) "query"
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.0.76
Claude Code Version
2.1.1
Platform
Google Vertex AI
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗