tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Anthropic Claude API > Claude Few-Shot Prompting Patterns

Claude Few-Shot Prompting Patterns

Author: Venkata Sudhakar

Few-shot prompting gives Claude examples of the desired input-output format before the actual task, dramatically improving output consistency for specialized formats. For ShopMax India, a product description generator that produces inconsistent formats - sometimes bullet points, sometimes paragraphs, sometimes starting with the price, sometimes not - creates extra editorial work. Adding 2-3 examples of the exact format you want locks Claude into that pattern reliably, even for unusual product types.

Few-shot examples are provided in the messages array as alternating user and assistant turns before the real query. Each example pair shows Claude a sample input and the ideal output for that input. The examples should be representative of the task variation, not cherry-picked easy cases. Dynamic few-shot selection - choosing examples at runtime based on similarity to the current input - outperforms static examples by 20-30% on classification and extraction tasks where different input types need different handling.

The following example shows ShopMax India using few-shot prompting to generate consistently formatted product descriptions, with static and dynamic example selection:


It gives the following output,

Input: Product: LG 50-inch 4K NanoCell TV | Price: Rs 44990 | Key feature: Dolby Vision
Output: Experience true-to-life colors in your Bangalore home with the LG 50-inch
4K NanoCell at Rs 44,990. Dolby Vision and HDR10 deliver Hollywood-quality picture
accuracy. Available on 0% EMI with ICICI and Axis cards.

Input: Product: Voltas 1T Window AC | Price: Rs 27990 | Key feature: Fast cooling for Delhi climate
Output: Designed for Delhi summers, the Voltas 1T Window AC at Rs 27,990 cools
your room in minutes even on 45-degree days. Trusted by Delhi households for
decades with easy installation and reliable performance.

Input: Product: Sony 43-inch Bravia Google TV | Price: Rs 38990 | Key feature: Built-in OTT apps
Output: Watch Netflix, Amazon Prime, and Hotstar without any extra device on the
Sony 43-inch Bravia Google TV at Rs 38,990. Perfect for Mumbai apartments where
space matters. Google TV learns your preferences for smarter content discovery.

For ShopMax India, maintain a library of 10-15 high-quality few-shot examples covering different product categories and output styles. When adding a new product category like air purifiers or water heaters, add 2-3 examples specific to that category before rolling out generation. Use dynamic example selection by embedding your examples and the current input, then selecting the 3 most similar examples at runtime - this is especially effective for the product description task since TV examples do not transfer well to AC descriptions without adaptation.


 
  


  
bl  br