SDKStructured outputs

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.json
syntic -p "summarise the open issues" --json-schema schema.json --output-format json

How 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 json it is also in the structured_output field next to result.
  • An answer that still does not match after the retry makes the run fail: is_error is 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.