schema-first-prompting
Schema-First Prompting
Design the Pydantic model first, then write the prompt. The model is the structural contract; the prompt carries only what the schema cannot encode. Be brief, clean, elegant, and internally consistent.
1. Don't say the same thing twice
Schema owns shape — names, types, nesting, constraints. Prompt owns intent — tone, audience, rhetorical rules. If the same fact lives in both places, delete the duplicate.
| What | Where |
|---|---|
| Shape, types, limits | Pydantic model (Field, validators) |
| Fixed values from variant/slot | Code, after validation |
| Rhetorical / quality rules | Prompt |
| Which schema to use | Caller (conditional model + prompt) |
When the API supports structured output or tool parameters tied to JSON Schema, put structure there. Keep user/system messages to task, context, and behavior.
If native structured output is unsupported and you must inject the schema into the prompt, avoid injecting raw JSON Schema (model_json_schema()), as it is highly token-inefficient. Instead, use type-definition pseudo-code (TypeScript-style interfaces), which can reduce token usage by up to 60% while being clearer to the model's attention mechanism.