Back to Blog
11 min read

One-Shot vs Few-Shot Prompting: Generating Complex Data Structures with AI

Learn when to use one-shot vs few-shot prompting for generating complex JSON structures. Includes comparison tables, examples, and proven templates for reliable AI data generation.

TL;DR: One-shot prompting works for simple structures; few-shot prompting (providing 2-3 examples) dramatically improves accuracy for complex, nested JSON. Use few-shot when structure matters more than content.

The Problem: Inconsistent AI-Generated Structures

You need to generate 100 product records in JSON format. You write a prompt, and the first result looks perfect. But records 50-100 have different field names, inconsistent nesting, and mixed data types.

The cost: Hours of manual data cleanup and broken automation scripts.

Understanding Shot-Based Prompting

What is "Shot" in Prompting?

A "shot" is an example you provide to the AI before asking it to perform a task.

  • Zero-Shot: No examples, just instructions
  • One-Shot: One example
  • Few-Shot: 2-5 examples
  • Many-Shot: 6+ examples

Why Examples Matter

LLMs learn patterns from examples faster than from descriptions. Showing beats telling.

Description (Zero-Shot):

Generate a user object with name, email, and age fields.

Example (One-Shot):

Example: {"name":"Alice","email":"alice@example.com","age":30}

Now generate one for Bob, age 25, email bob@example.com

The second approach produces more consistent results.

One-Shot Prompting

When to Use One-Shot

Use one-shot when:

  • Structure is simple (flat objects, 3-5 fields)
  • Field names are obvious
  • Data types are clear
  • You need speed over precision

Don't use one-shot when:

  • Structure is nested or complex
  • Field naming is ambiguous
  • Multiple valid formats exist
  • Consistency is critical

One-Shot Template

You are a JSON generator. Output ONLY valid JSON.

Example:
{EXAMPLE_JSON}

Task: Generate similar JSON for {DESCRIPTION}

Output:

One-Shot Example: Simple User Object

Prompt:

You are a JSON generator. Output ONLY valid JSON.

Example:
{"userId":"USR001","name":"Alice Smith","email":"alice@company.com","role":"admin"}

Task: Generate similar JSON for Bob Johnson, email bob@company.com, role user, ID USR002

Output:

AI Response:

{"userId":"USR002","name":"Bob Johnson","email":"bob@company.com","role":"user"}

Success Rate: ~85% for simple structures

Few-Shot Prompting

When to Use Few-Shot

Use few-shot when:

  • Structure is complex or nested
  • You need exact field naming
  • Data relationships matter
  • Consistency is non-negotiable
  • Edge cases exist

Few-Shot Template

You are a JSON generator. Output ONLY valid JSON matching these examples.

Example 1:
{EXAMPLE_1}

Example 2:
{EXAMPLE_2}

Example 3:
{EXAMPLE_3}

Pattern: {EXPLAIN_PATTERN}

Task: Generate similar JSON for {DESCRIPTION}

Output:

Few-Shot Example: Nested E-commerce Order

Prompt:

You are a JSON generator. Output ONLY valid JSON matching these examples.

Example 1:
{"orderId":"ORD-001","customer":{"name":"Alice","email":"alice@example.com"},"items":[{"sku":"LAPTOP-001","qty":1,"price":999.99}],"total":999.99}

Example 2:
{"orderId":"ORD-002","customer":{"name":"Bob","email":"bob@example.com"},"items":[{"sku":"MOUSE-001","qty":2,"price":29.99},{"sku":"KEYBOARD-001","qty":1,"price":79.99}],"total":139.97}

Example 3:
{"orderId":"ORD-003","customer":{"name":"Charlie","email":"charlie@example.com"},"items":[{"sku":"MONITOR-001","qty":1,"price":299.99}],"total":299.99}

Pattern: orderId format is ORD-XXX, customer is nested object, items is array, total is sum of (qty * price)

Task: Generate order for customer Dana (dana@example.com), 3x CABLE-001 at $9.99 each, order ID ORD-004

Output:

AI Response:

{"orderId":"ORD-004","customer":{"name":"Dana","email":"dana@example.com"},"items":[{"sku":"CABLE-001","qty":3,"price":9.99}],"total":29.97}

Success Rate: ~95% for complex structures

Comparison Table

AspectOne-ShotFew-Shot
Examples Provided12-5
Best ForSimple structuresComplex/nested structures
Consistency85%95%+
Setup TimeFastModerate
Token CostLowMedium
Edge Case HandlingPoorExcellent
Field Naming AccuracyGoodExcellent
Nested Structure SupportLimitedStrong

Advanced Techniques

Technique 1: Progressive Complexity

Start with simple examples, increase complexity:

Example 1 (basic):
{"id":1,"name":"Alice"}

Example 2 (add field):
{"id":2,"name":"Bob","email":"bob@example.com"}

Example 3 (add nesting):
{"id":3,"name":"Charlie","email":"charlie@example.com","profile":{"age":30,"city":"NYC"}}

Now generate for Dana, ID 4, email dana@example.com, age 25, city SF

Technique 2: Contrast Examples

Show what TO do and what NOT to do:

✅ Correct format:
{"userId":"USR001","active":true}

❌ Incorrect format:
{"user_id":"USR001","active":"true"}

Note: Use camelCase, booleans not strings

Now generate for user ID USR002, inactive status

Technique 3: Edge Case Examples

Include edge cases in your examples:

Example 1 (normal):
{"name":"Alice","items":["A","B","C"]}

Example 2 (empty array):
{"name":"Bob","items":[]}

Example 3 (single item):
{"name":"Charlie","items":["X"]}

Now generate for Dana with no items

Test Your Generated Structures

Paste your AI-generated JSON into our validator to verify structure consistency across multiple generations.

Validate Structure →

Real-World Use Cases

Use Case 1: API Response Mocking

Scenario: Generate 10 mock user API responses

Few-Shot Prompt:

Generate JSON matching this pattern.

Example 1:
{"status":200,"data":{"userId":"a1b2c3","username":"alice","verified":true},"timestamp":"2024-01-15T10:30:00Z"}

Example 2:
{"status":200,"data":{"userId":"d4e5f6","username":"bob","verified":false},"timestamp":"2024-01-15T10:31:00Z"}

Generate 10 similar responses with unique IDs, varied usernames, random verified status, sequential timestamps (1 minute apart starting from 2024-01-15T10:32:00Z)

Use Case 2: Test Data Generation

Scenario: Create test data for a user management system

Few-Shot Prompt:

Example 1:
{"id":1,"profile":{"firstName":"Alice","lastName":"Smith"},"permissions":["read","write"],"createdAt":"2024-01-01"}

Example 2:
{"id":2,"profile":{"firstName":"Bob","lastName":"Jones"},"permissions":["read"],"createdAt":"2024-01-02"}

Example 3:
{"id":3,"profile":{"firstName":"Charlie","lastName":"Brown"},"permissions":["read","write","admin"],"createdAt":"2024-01-03"}

Generate 5 more users with IDs 4-8, realistic names, varied permissions, sequential dates

Use Case 3: Configuration File Generation

Scenario: Generate environment-specific configs

Few-Shot Prompt:

Example 1 (dev):
{"env":"development","database":{"host":"localhost","port":5432,"ssl":false},"logging":{"level":"debug","file":"/var/log/dev.log"}}

Example 2 (staging):
{"env":"staging","database":{"host":"staging-db.example.com","port":5432,"ssl":true},"logging":{"level":"info","file":"/var/log/staging.log"}}

Example 3 (prod):
{"env":"production","database":{"host":"prod-db.example.com","port":5432,"ssl":true},"logging":{"level":"error","file":"/var/log/prod.log"}}

Generate config for "testing" environment with test-db.example.com, SSL enabled, warning level logging

Pro Tips

Tip 1: Use Diverse Examples

Don't make all examples too similar:

Too similar:

{"name":"Alice","age":30}
{"name":"Bob","age":31}
{"name":"Charlie","age":32}

Diverse:

{"name":"Alice","age":30}
{"name":"Bob","age":25}
{"name":"Charlie","age":45}

Tip 2: Highlight Patterns Explicitly

After examples, state the pattern:

Examples: [YOUR_EXAMPLES]

Pattern to follow:
- IDs are always uppercase with hyphens
- Dates are ISO 8601 format
- Arrays can be empty but never null
- All prices have 2 decimal places

Tip 3: Include Boundary Cases

Example 1 (minimum):
{"items":[],"total":0}

Example 2 (typical):
{"items":[{"id":1,"qty":2}],"total":50.00}

Example 3 (maximum):
{"items":[{"id":1,"qty":100},{"id":2,"qty":100}],"total":10000.00}

Tip 4: Validate Consistency

After generation, check:

  1. All objects have same keys
  2. Data types match across examples
  3. Nesting depth is consistent
  4. Field naming convention is uniform

Use our JSON Validator to compare structures.

Common Mistakes

Mistake 1: Too Many Examples

Problem: 10+ examples confuse the model

Solution: 2-5 examples is the sweet spot

Mistake 2: Contradictory Examples

Problem:

Example 1: {"user_id": 1}
Example 2: {"userId": 2}

Solution: Ensure consistent naming across all examples

Mistake 3: No Pattern Explanation

Problem: Examples without context

Solution: Always explain the pattern after examples

Mistake 4: Ignoring Edge Cases

Problem: Only showing "happy path" examples

Solution: Include empty arrays, null handling, boundary values

Choosing the Right Approach

Decision Tree

Is the structure simple (flat, <5 fields)?
├─ Yes → Try one-shot first
└─ No → Use few-shot

Did one-shot produce consistent results?
├─ Yes → Stick with one-shot
└─ No → Switch to few-shot

Are there edge cases or special rules?
├─ Yes → Use few-shot with edge case examples
└─ No → One-shot may suffice

Is this for production use?
├─ Yes → Always use few-shot for reliability
└─ No → One-shot is fine for prototyping

Conclusion

Few-shot prompting is your secret weapon for generating complex, consistent JSON structures. While one-shot works for simple cases, investing in 2-3 quality examples pays dividends in accuracy and consistency.

Key Takeaways:

  • One-shot: Fast, good for simple structures
  • Few-shot: Reliable, essential for complex structures
  • Always include edge cases in examples
  • Explain patterns explicitly
  • Validate output for consistency

Master Template:

Examples:
{EXAMPLE_1}
{EXAMPLE_2}
{EXAMPLE_3}

Pattern: {PATTERN_EXPLANATION}

Task: {YOUR_TASK}

Output:

Validate Your AI-Generated Data

Use our JSON Formatter to ensure consistency across all your AI-generated structures.

Check Consistency →