Policy state changes which schema the host sends through Ollama's format
field, or whether it sends none. This example shows that host-side
schema-selection behavior without relying on prompt reinjection.
Flow:
Context Compiler state -> host schema decision -> Ollama format request -> model call
The host reads compiled policy state, picks a JSON Schema (or none), and sends that choice through Ollama's format field.
- Context Compiler provides deterministic state transitions.
- The host integration decides whether to request a schema.
- Ollama structured output is a runtime request made by the host.
- If policy state is unknown or insufficient, the host requests no schema.
- The host will not request the
shell_commandschema. - The host may still request a different schema when policy supports it (for example,
python_script). - This does not block normal language discussion about shell commands.
Given policy state:
use python_script
prohibit shell_command
this host selects python_script schema and does not request shell_command schema.
Tests verify schema selection behavior only:
- compiler state -> selected schema (or no schema)
- contradiction handling stays in compiler
clarify
Tests do not assert exact model wording.
uv run python python/examples/schema_selection/ollama_structured_output/example.pyexport RUN_OLLAMA_SMOKE=1
export OLLAMA_MODEL=llama3.1
uv run python python/examples/schema_selection/ollama_structured_output/example.pyWhen smoke mode is enabled, the host sends the selected JSON Schema through Ollama format.