Structured outputs
A print run (-p) can require its final answer to be JSON that matches a JSON Schema. Pass the schema with --json-schema, either inline or as the path to a schema file:
syntic -p "list the public functions in src/lib.rs" \
--json-schema '{"type":"array","items":{"type":"string"}}' \
--output-format json > result.jsonsyntic -p "summarise the open issues" --json-schema schema.json --output-format jsonHow the check works
- A value that starts with
{is read as inline JSON. Anything else is read as a file path. The schema must be a JSON object. - The agent is told the schema before it starts, and it is asked to answer with JSON only.
- The final answer is checked against the schema. A Markdown code fence or a short lead-in around the JSON is tolerated.
- On a mismatch the agent gets one more turn, with the validation error, to correct its answer.
- A valid answer is printed as JSON. With
--output-format jsonit is also in thestructured_outputfield next toresult. - An answer that still does not match after the retry makes the run fail:
is_erroris true and the exit code is not zero.
Check is_error and the exit code before you read structured_output. See Examples for that pattern.
Related
- Streaming vs single mode explains the one-shot result and the stream.
- Configuration lists the other run flags.