Skip to content

Structured output

Lime can constrain a turn’s response to a JSON Schema. Useful when you’re piping Lime into another tool, building a pipeline, or want a model to emit a specific data shape.

How it works

Pass --output-schema FILE at launch. The schema is loaded, validated, and forwarded to the active provider as a structured-output constraint (or, where the provider does not natively support schema constraints, enforced by Lime via the structured_output tool).

Terminal window
lime --output-schema ./schema.json --resume latest /…

The exact wire mechanism depends on the provider:

ProviderHow the schema is enforced
OpenAIForwarded as response_format.json_schema on the Responses API.
AnthropicEnforced via the structured_output tool in the system prompt.
GeminiForwarded as responseSchema on generateContent.
OpenAI-compatibleForwarded as response_format if the preset declares schema support; otherwise enforced via structured_output.

Schema file shape

The file must be a single JSON document containing a JSON Schema (Draft 2020-12). Top-level type is typically "object" with "required" and "properties".

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "FailingTests",
"type": "object",
"required": ["count", "tests"],
"properties": {
"count": { "type": "integer", "minimum": 0 },
"tests": {
"type": "array",
"items": {
"type": "object",
"required": ["name", "file"],
"properties": {
"name": { "type": "string" },
"file": { "type": "string" },
"line": { "type": "integer" }
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}

Worked example

Terminal window
cat > /tmp/failing-tests.json <<'EOF'
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["tests"],
"properties": {
"tests": {
"type": "array",
"items": {
"type": "object",
"required": ["name", "file"],
"properties": {
"name": { "type": "string" },
"file": { "type": "string" }
},
"additionalProperties": false
}
}
},
"additionalProperties": false
}
EOF
lime --output-schema /tmp/failing-tests.json

The streamed response is incremental but converges to a single JSON document that validates against the schema.

Caveats

  • Schema enforcement is a constraint on the final answer, not a guarantee at every streaming chunk. Do not parse partial chunks as JSON.
  • Some openai-compat services do not advertise schema support; Lime falls back to the tool-based path automatically.
  • Reasoning summaries and tool calls are not constrained — the schema applies to the model’s final visible output only.