#prompting#llm#softwaredevelopment#generativeai
Basic Prompting Techniques
Tomer Raitz
Jan 22ā¢3 min read
There are a few basic prompting techniques that help us design our prompts more effectively, ensuring the LLM understands our intent accurately.
1. Zero-Shot Prompting
In this technique, we do not provide any examples to the LLM (zero). We rely solely on the model's pre-trained knowledge.
When to use it:
- For simple, straightforward tasks.
- When you want to test the model's inherent knowledge or domain expertise without biasing it.
Example:
šPython12345def add(x,y): answer = x + y return answer prompt: Explain what this code does.
2. One-Shot Prompting
In this technique, we provide exactly one example to the LLM.
When to use it:
- When we need a specific output structure (like JSON or a specific list format).
- When the task is slightly ambiguous, and one example clarifies the desired style or logic.
Example:
š¦JSON1234567891011121314Prompt: Task: Find weather for a city and output in JSON. Example 1 (The Shot): Input: "Weather in London" Output: { "city": "London", "weather": "Cloudy", "temp": 15 } Main Request: Input: "Weather in New York" Output:
3. Few-Shot Prompting
In this technique, we provide more than one example to the LLM (usually 2-5).
When to use it:
- For complex tasks where a single example isn't enough to capture the pattern.
- When dealing with text that can have more then one meaning.
Example:
šMarkdown123456789101112prompt = """ Task: Extract food items and their prices from the text into a JSON format. Text: "I bought a burger for $5 and fries for $2." Output: [{"item": "burger", "price": 5}, {"item": "fries", "price": 2}] Text: "The salad cost $8, and the soda was $1.50." Output: [{"item": "salad", "price": 8}, {"item": "soda", "price": 1.5}] Text: "We ordered a large pizza for $15 and two cokes for $3." Output: """
4. Role Prompting
In this technique, you ask the LLM to act like a specific persona, character, or profession.
When to use it:
- Adjusting Complexity for the Audience: Providing different explanations for different types of audiences.
Example:
šMarkdown1234567891011# Vibki for developers who know technical concepts prompt = """ Role: You are a Tech Lead. Your main goal is to mentor and explain difficult concepts to developers. """ # Vibki For Kids prompt = """ Role: You are a school teacher. Your main goal is to explain difficult concepts to kids. """
- Tone of Voice: When we want the LLM to speak in a specific style, for example: professional, humorous, etc.
Example:
šMarkdown123prompt = """ Role: You are a copywriter. Your writing style is humorous. Write a post for LinkedIn. """
- Professional Point of View: When we want the LLM to think like a specific professional.
Example:
šMarkdown123prompt = """ Role: You are a Headhunter with 10 years of experience. Help me write my CV. """
- Training and Simulation: When we want to practice a scenario.
Example:
šMarkdown123prompt = """ Role: You are a Backend Team Leader at Google. Let's simulate a technical interview. """
In the next posts, we are going to explore more advanced ways of prompting techniques.
Comments
0 comments
No comments yet. Be the first to share your thoughts!

