Few-shot prompting guides a large language model by placing multiple task examples in the prompt before the new input. The examples clarify the expected pattern and can improve the relevance or accuracy of the response. section 16.2.3
Distinguish it from nearby prompting approaches:
- Zero-shot prompting supplies an instruction without examples. section 16.2.3
- One-shot prompting supplies one example, while few-shot prompting supplies multiple examples. section 16.2.3
- Separators such as // or -> can divide each input from its expected output, provided the format stays consistent. section 16.2.3
Classifying sentiment
Provide labeled examples such as “The movie is awesome! // Positive” and “It is so bad! // Negative,” then add “How horrible the movie is! //”. The model can infer the pattern and return “Negative.” section 16.2.3
prompt = """ The movie is awesome! // Positive It is so bad! // Negative Wow, the movie was incredible! // Positive How horrible the movie is! // """ res=llm.invoke(prompt) print(res)
Run a compact sentiment-classification prompt with three labeled examples and an unlabeled review. section 16.2.3

















