Phase 1: Advanced Prompt Engineering for Agents · 50 min · OpenAI SDK · Python · NumPy
Few-Shot Prompting for Tool Use
The fix for wrong tool calls is rarely a bigger model — it's 3 examples in your prompt.
Hiring signal: Senior AI engineers maintain libraries of few-shot examples and test them like unit tests. Knowing how to build and measure a few-shot library is a concrete portfolio skill.
What you will learn
- Write few-shot examples that anchor tool selection to the correct triggers
- Apply negative examples that show what NOT to call
- Build a few-shot library for a multi-tool agent and measure its impact on tool selection accuracy
The Problem
You defined a tool called search_orders. The model keeps calling it to answer questions about shipping policies, even though you have a separate get_policy tool for that.
You update the search_orders description to say "Use this for order-specific queries, not policy questions." The problem improves but doesn't disappear. A few days later you notice the model is now calling get_policy for order lookups when users phrase things like "what's the status of my recent order?"
The fundamental issue: descriptions tell the model what a tool IS. Examples show the model when to USE it. For ambiguous cases, examples are more reliable than descriptions.
Why agents need few-shot more than chatbots
For a chatbot, a wrong answer is annoying. For an agent with write access, calling the wrong tool can send the wrong email, delete the wrong record, or charge the wrong card. The cost of tool selection errors is orders of magnitude higher.
Why Few-Shot Works for Agents
When the model processes few-shot examples, it's not just memorizing — it's pattern-matching against the examples before generating its response. Concrete examples anchor the model to your specific vocabulary, scope, and edge cases in a way that descriptions alone cannot.
Compare:
Instruction only:
Use get_order_status for questions about specific customer orders.
Use get_shipping_policy for questions about shipping rules and timelines.
Instruction + example:
Use get_order_status for questions about specific customer orders.
Use get_shipping_policy for questions about shipping rules and timelines.
Example:
User: "What's your standard return window?"
→ Call: get_shipping_policy(topic="return_policy")
[NOT get_order_status — user hasn't mentioned a specific order]
The example makes concrete what "specific customer orders" means in practice — it needs an order ID or reference to a particular purchase.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Writing Effective Few-Shot Examples, Negative Examples, Dynamic Few-Shot Selection, Build It, What to Practice — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy