Force a structured JSON result

exec & automation

// what it does

--output-schema points at a JSON Schema file and constrains the final answer to conform to it, turning Codex into a structured extractor that returns valid JSON. Pair it with -o to save the result straight to a file.

// shell

$ codex exec "extract project metadata" --output-schema schema.json -o meta.json

// gotcha

The schema file must be valid JSON Schema, and the model is held to it — an over-strict schema can make Codex fail to produce any answer. Start loose and tighten it as you go.

// resources