# ❌ Instructions only — produces variable nesting
instructions = """
Extract parties from contracts. Return JSON with:
- parties: array of party objects with name, role, and address
- Each party may have a 'represented_by' attorney field
"""
# Result: Claude nests 'represented_by' differently each time
# ✅ Examples show exact structure — produces consistent output
few_shot = """
Extract contract parties. Follow this EXACT structure:
EXAMPLE 1 (two parties, one with attorney):
Contract: "Between Acme Corp ('Buyer') and TechCo Inc ('Seller')
represented by counsel Smith & Jones LLP, effective January 2024."
Output:
{
"parties": [
{
"name": "Acme Corp",
"role": "buyer",
"represented_by": null
},
{
"name": "TechCo Inc",
"role": "seller",
"represented_by": "Smith & Jones LLP"
}
],
"party_count": 2
}
EXAMPLE 2 (three parties, none with attorneys):
Contract: "Agreement between GlobalCorp ('Licensor'), RegionCo ('Licensee'),
and PayCo ('Payment Agent')."
Output:
{
"parties": [
{"name": "GlobalCorp", "role": "licensor", "represented_by": null},
{"name": "RegionCo", "role": "licensee", "represented_by": null},
{"name": "PayCo", "role": "payment_agent", "represented_by": null}
],
"party_count": 3
}
Now extract parties from: {contract_text}
"""
Example 1 explicitly teaches null for missing represented_by — preventing Claude from omitting the field entirely or inventing an attorney.
# ❌ Inconsistent — creates inconsistent output
examples = [
# Example 1: date as string
{"effective_date": "2024-01-15"},
# Example 2: date as object
{"effective_date": {"year": 2024, "month": 1, "day": 15}},
]
# Claude will sometimes use one format, sometimes the other
# ✅ Consistent — output is predictable
examples = [
{"effective_date": "2024-01-15"}, # ISO string
{"effective_date": "2024-03-22"}, # ISO string
{"effective_date": None}, # null when missing
]
Key Takeaways
- Show structure rather than describe it for complex nesting
- null/missing cases must be in examples — prevents fabrication
- Identical format across all examples — no variation
- Two examples minimum to show pattern generalization
- Combine with schema validation for production safety