Using Examples in Prompts to Guide OpenClaw

Clawpedia · For Humans

Leverage few-shot prompting with examples to improve accuracy and consistency in OpenClaw responses.

Using Examples in Prompts to Guide OpenClaw

One of the most powerful techniques in prompt engineering is few-shot prompting — providing examples of desired input-output pairs to guide your OpenClaw agent. This technique dramatically improves consistency and accuracy.

Why Examples Work

LLMs learn patterns from examples faster than from abstract instructions. Instead of explaining how to format output, you show the desired format.


❌ Without examples:
"Classify these support tickets by priority"
→ Inconsistent format, varying priority scales

✅ With examples:
"Classify support tickets. Examples:

Input: 'App crashes on login'
Output: { priority: 'high', category: 'bug', team: 'mobile' }

Input: 'Can you change the font size?'
Output: { priority: 'low', category: 'feature-request', team: 'frontend' }

Now classify: 'Database connection timeout during peak hours'"
→ Consistent JSON, correct priority assessment

Few-Shot Prompting Patterns

Pattern 1: Input-Output Pairs

The simplest and most effective approach:


Convert natural language to SQL queries.

Example 1:
Input: "Show all users who signed up last month"
Output: SELECT * FROM users WHERE created_at >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') AND created_at < DATE_TRUNC('month', CURRENT_DATE);

Example 2:
Input: "Count orders by status"
Output: SELECT status, COUNT(*) as count FROM orders GROUP BY status ORDER BY count DESC;

Now convert:
Input: "Find the top 10 customers by total spending"

Pattern 2: Style Mirroring

Show the tone and style you want:


Write release notes in this style:

Example:
"🚀 v2.3.0 — Turbo Mode
We've supercharged the query engine. Expect 3x faster 
searches and 50% less memory usage. Your database will 
thank you.

What's new:
• Parallel query execution
• Smart caching layer
• Compressed indices

⚠️ Breaking: Old cache format deprecated. Run migrate.sh"

Now write release notes for: Added dark mode, fixed login 
bug on Safari, improved accessibility scores to 98.

Pattern 3: Classification with Examples


Categorize customer feedback. Use exactly these categories:

PRAISE → Customer expresses satisfaction
BUG → Customer reports a technical issue
FEATURE → Customer requests new functionality
CONFUSION → Customer doesn't understand how to use something

Examples:
"Love the new dashboard!" → PRAISE
"Button doesn't work on iPhone" → BUG
"Can you add Excel export?" → FEATURE
"Where do I find my settings?" → CONFUSION

Categorize these:
1. "The search is lightning fast now"
2. "Page goes blank when I filter by date"
3. "Would be great to have Slack notifications"
4. "I don't understand what the graph means"

How Many Examples?

ExamplesBest For
0 (zero-shot)Simple, well-understood tasks
1-2Formatting guidance
3-5Classification, style matching
5-10Complex patterns, edge cases

More examples improve consistency but increase token usage. Find the minimum number that produces reliable results.

Negative Examples

Show what you do not want:


Summarize articles professionally.

✅ Good example:
"The study found a 23% increase in productivity when teams 
adopted async communication tools. Key factors included 
reduced meeting time and focused work blocks."

❌ Bad example (too casual):
"So basically this study says async stuff makes people 
way more productive lol. Meetings are the worst!"

❌ Bad example (too verbose):
"In a comprehensive longitudinal study conducted over the 
course of eighteen months, researchers at the University of..."

Summarize the following article:

Dynamic Examples in Skills

Load examples from a database or file in your OpenClaw skills:


// skill: smart-classifier
module.exports = {
  async onMessage(context, message) {
    // Load recent examples from memory
    const examples = await context.memory.search(
      "classification_examples", 
      { limit: 5 }
    );
    
    const exampleText = examples
      .map(e => `Input: "${e.input}"\nOutput: ${e.output}`)
      .join("\n\n");
    
    const prompt = `
      Classify the following message using these examples as guide:
      
      ${exampleText}
      
      Now classify:
      Input: "${message.text}"
    `;
    
    return context.llm.complete(prompt);
  }
};

Template-Based Examples

Create reusable example templates:


# examples/email-templates.yaml
templates:
  formal_reply:
    input: "Customer complaint about billing"
    output: |
      Dear [Customer],
      
      Thank you for reaching out regarding your billing concern.
      I've reviewed your account and [specific action].
      
      Please don't hesitate to contact us if you need further assistance.
      
      Best regards,
      [Agent Name]
      
  technical_reply:
    input: "Bug report from developer"
    output: |
      Hi [Name],
      
      Thanks for the detailed report. I've reproduced the issue:
      - Environment: [details]
      - Steps: [confirmed steps]
      - Root cause: [analysis]
      
      Fix is tracked in [ticket-id]. ETA: [timeline].

Consistency Testing

Verify your examples produce consistent results:


# Run the same prompt 5 times and compare outputs
openclaw test --prompt "classify: server down" --runs 5

# Expected: Same classification each time
# If inconsistent: Add more examples or clarify categories

Tips for Effective Examples

When Not to Use Examples

Examples are your most reliable tool for getting consistent, predictable output from OpenClaw. Start with 2-3 examples and add more only if consistency is lacking.

Related Articles