# Structured output contract

> Answer only in this JSON, or in an error object; a validator snippet and the Ollama format field for pipelines.

Page: https://videotomd.com/b/text-structured-output-contract/
Tool: Any AI · Tags: json, structured-output, pipelines, validation · 316 words, about 411 tokens
Pills: free · Python · ran in Claude Code · self-check · done check · checked 2026-10-12 · Any AI · Any text chat · Ollama · LM Studio · Open WebUI · Claude Code · chat only · on demand · 7B ok · data · coding

## Recipe

- Kind: template
- Stage: not set
- Loads: on demand
- Works in: Any AI, Any text chat, Ollama, LM Studio, Open WebUI, Claude Code
- Needs: chat only
- Bring: Python
- Cost: free
- Model: 7B ok
- Tested in: Claude Code
- Checked: 2026-10-12
- For: data, coding

## When this is useful
- A script reads the model's answer and breaks on "Sure! Here is the JSON:".
- You classify or extract in a loop and need every reply to parse.
- A small local model drifts from the format after a few turns.


## Change it to
- Chat-only: paste the contract with the first message; copy the reply into the validator by hand (the any-chat row).
- LM Studio: put the contract in the preset's system prompt; use the server's `response_format` when the model supports it (the lm-studio row).
- 7B model: three fields or fewer, one example, and `format: json` on; ask for one object per request, never a list.


## If your AI needs to look something up
- The schema form of `format`: fetch https://docs.ollama.com/capabilities/structured-outputs and quote the request body.


## Put it here

Loads on demand: paste or attach it when the task comes up. To have it every session, put it where your tool reads instructions:

- Any AI: Coding agent: save as AGENTS.md in the project root (read natively by Codex, Cursor, Copilot, Gemini CLI, Kiro, Devin, Cline, Roo, OpenHands, OpenCode, Goose, Amp, Zed, Warp, Junie, Factory and Jules; Claude Code when no CLAUDE.md exists; Aider with --read). Chat: paste it first. Reload: new session. Check it loaded: ask it to repeat one rule from the file. Source: https://agents.md/ (checked 2026-10-12).
- Any text chat: Paste the whole file as your first message, then your task. A chat cannot read files or run commands: it must hand you the command and wait for the output. Reload: paste it again in a new chat. Check it loaded: ask it to repeat one rule from the file; a general answer means it is not in context. Source: https://videotomd.com/use-with-your-ai/ (checked 2026-10-12).
- Ollama: Put the text in a Modelfile as SYSTEM """...""" with FROM <model> and PARAMETER num_ctx <n>, then `ollama create <name> -f Modelfile` and run <name>. Chat-only: paste it as the first message instead. Reload: ollama create again. Check it loaded: `ollama show --modelfile <name>` prints the SYSTEM; `ollama ps` shows the loaded context size. Source: https://docs.ollama.com/modelfile (checked 2026-10-12).
- LM Studio: Paste the text into the System Prompt field, set the context length, and save it as a preset so it survives a restart. Server: http://localhost:1234/v1. Reload: reload the preset. Check it loaded: the preset in the app; ask the model to repeat one rule. Source: https://lmstudio.ai/docs/app/presets (checked 2026-10-12).
- Open WebUI: Workspace → Models → your model → System Prompt: paste the text and save. Long reference goes in Knowledge and is retrieved, not always loaded. Reload: start a new chat. Check it loaded: the model's System Prompt field; ask the model to repeat one rule. Source: https://docs.openwebui.com/features/workspace/models (checked 2026-10-12).
- Claude Code: Save as CLAUDE.md in the project root, or .claude/CLAUDE.md. Other agents share the repo: put the shared rules in AGENTS.md and make CLAUDE.md one line, @AGENTS.md. Commit it. Start a new session: the file is read at launch. Reload: new session (or /memory to open the files). Check it loaded: /context lists the Memory files it read; /skills, /agents, /hooks list the rest; the InstructionsLoaded hook event fires once per loaded instruction file. Source: https://code.claude.com/docs/en/memory (checked 2026-10-12).

## Access

Membership: plans at https://videotomd.com/pricing/, or email then a plan at https://videotomd.com/b/text-structured-output-contract/. A member's browser downloads the file there; an AI without that session needs the member to attach it.
