PM-301c · Module 2

Schema Enforcement Patterns

5 min read

When API-level schema enforcement is unavailable or insufficient, prompt-level patterns can enforce schema compliance. These patterns exploit the model's strong tendency to complete structured patterns — once a partial structure is established in the prompt, the model fills it in consistently.

# PATTERN 1: Schema + Prohibition
Return JSON conforming to this schema. Do not add fields not in the schema.
Do not include any text outside the JSON object.
Schema: { "name": string, "score": number (0-100), "tier": "bronze"|"silver"|"gold" }

# PATTERN 2: Partial Fill (model completes the structure)
Return the following JSON with values filled in:
{
  "name": "

[Model is prompted to complete the structure — strong compliance signal]

# PATTERN 3: Output Section Anchor
After your analysis, output the result in this exact format:

OUTPUT:
{
  "name": "[lead name]",
  "score": [0-100],
  "tier": "[bronze|silver|gold]"
}

Do not include any text after the closing brace.

# PATTERN 4: Explicit Field-by-Field Instruction
Your response must be a JSON object containing:
- "name": the lead's full name as a string
- "score": lead quality score as an integer from 0 to 100
- "tier": exactly one of the strings "bronze", "silver", or "gold"
No other fields. No prose. JSON only.

Do This

  • Combine explicit schema with "no other fields" prohibition
  • Use the partial-fill pattern for high-compliance requirements
  • Position schema specification immediately before the output anchor
  • Test each enforcement pattern against adversarial inputs before deploying

Avoid This

  • Rely on the model to infer schema from context without explicit specification
  • Place schema instructions far from the output prompt — they lose salience
  • Use multiple conflicting schema specifications in the same prompt
  • Assume enforcement patterns hold under user manipulation — test adversarially