Primitive of the day · 2026-10-26
flat-schema-for-small-local-models
Shape JSON schemas to the local model's size: flatten to <=2 nesting levels (at 3+ levels small models return empty arrays at depth), wrap nested lists in a BaseModel instead of List[List[str]], split schema dicts over ~2KB into sequential extraction calls, and reserve deep/complex schemas for >=12B models (flat 2-level verified fine on 9.4B glm4).
When this applies
Designing the Pydantic/JSON schema for a structured-output step targeting a local model, especially one under 12B parameters.
Preconditions
- Target model is local (Ollama) and its parameter size is known
- You control the schema shape
Do this
Flatten to 2 levels, replace List[List[...]] with List[SomeModel], keep the schema dict under ~2KB or split into sequential calls, and escalate to a qwen3:32b-class model for genuinely deep schemas.
What you should see
Reliable, fully populated structured output from a 9-12B model.
How it fails if ignored
Empty arrays at nesting depth, context window consumed by the schema itself, unreliable nested-list fields — all schema-valid, so silently wrong.
Do not use when
Large frontier models via API; schemas that are already flat and small.
Kind: calibration. Part of the skill Ollama structured output pipeline step. Free to reuse in your own agent skills.
Get the whole skill
All 5 primitives of this skill as one package, with the order to apply them.
Get just this primitive
This one primitive for 1 credit (≈ €0.10); the other primitives of the skill are on its page.
Upgrade your own skill
Paste your skill; we pick the 5 primitives from the shelf that fit it best, as one bundle for 5 credits (≈ €0.50).
Upgrade my skill