Skip to main content

surface_structured_output

Function surface_structured_output 

Source
pub fn surface_structured_output(result: &mut QueryResult)
Expand description

Surface --json-schema structured output cleanly (#317).

In practice claude delivers the schema-constrained answer as a fenced ```json block inside result.result and does NOT populate a structured_output field. This normalizes that: when the body is a single fenced block whose contents parse as JSON, the parsed value is inserted under result.extra["structured_output"] (so --json consumers read .result.structured_output directly) and result.result is replaced with the unfenced text (so .result.result and the default text body are clean too).

No-ops when structured_output is already present and non-null (a future wrapper/claude version may surface it natively), or when the body is not a single parseable fenced JSON block. The caller gates this on --json-schema so a normal answer containing a JSON code block is never reinterpreted as structured output.