Suppose an application must classify numbers using labels the model has never been given rules for. Without guidance, it cannot know what the labels mean. Few-shot learning puts several labeled examples directly in the prompt so the model can infer a pattern and apply it to new inputs. This is in-context learning, not fine-tuning. section 2.5.4 section 1.4.1
Teach a classification pattern
To classify numbers by divisibility by 5 and 7, include examples for neither divisor, each divisor alone, and both together. A sample can show the number, its divisibility, and its label: “70 // divisible by 5, divisible by 7 // Abra Kadabra.” The model then applies the pattern to numbers not shown in the examples. section 2.5.4
Build and check a few-shot prompt:
- State the task and supply examples in a consistent format, including the distinctions the model must learn. section 2.5.4
- Test the response rather than assuming the examples were enough: two palindrome examples still led the model to overlook 99 when summing palindromes. section 2.5.2
- If the task needs a procedure, add explicit steps; chain-of-thought examples pair sample answers with the logical steps used to reach them. section 2.5.2 section 2.5.6
prompt_input = """Classify the following numbers as Abra, Kadabra or Abra Kadabra: 3, 4, 5, 7, 8, 10, 11, 13, 35 Examples: 6 // not divisible by 5, not divisible by 7 // None 15 // divisible by 5, not divisible by 7 // Abra 12 // not divisible by 5, not divisible by 7 // None 21 // not divisible by 5, divisible by 7 // Kadabra 70 // divisible by 5, divisible by 7 // Abra Kadabra """ response = llm.invoke(prompt_input) print(response.content)
A complete prompt and invocation show the instruction, new inputs, five labeled examples, and the model call together. section 2.5.5
For reuse, keep examples separate from the prompt template and inject them with LangChain’s FewShotPromptTemplate instead of hardcoding them into one string. More examples can improve consistency, but they also increase token costs. Examples guide the desired response pattern; they do not guarantee a correct answer. section 2.5.5 section 2.7 section 2.5.2
The same technique fits application prompts: three examples help select a research assistant and produce JSON, while schema and sample records can help a model generate SQL with fewer invented table or column names. When answers need user-specific or enterprise facts, prompt examples alone are not a substitute for retrieving that information. section 4.5.1 section 10.3 section 1.4.1

















