Loading...

Loading...

Basic Prompting Techniques
Loading like and share buttons...
#prompting#llm#softwaredevelopment#generativeai

Basic Prompting Techniques

Tomer Raitz
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:

🐍Python
1
2
3
4
5
def 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:

πŸ“¦JSON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Prompt:
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:

πŸ“Markdown
1
2
3
4
5
6
7
8
9
10
11
12
prompt = """
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:

πŸ“Markdown
1
2
3
4
5
6
7
8
9
10
11
# 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:

πŸ“Markdown
1
2
3
prompt = """
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:

πŸ“Markdown
1
2
3
prompt = """
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:

πŸ“Markdown
1
2
3
prompt = """
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.

Enjoyed this post?

Get the next one in your inbox. No spam, unsubscribe any time.

Comments

0 comments

Enter your comment. Maximum 2000 characters.

No comments yet. Be the first to share your thoughts!
Vibki logo wave icon
Vibki Surfing Bot
Vibki

Vibki is a developer blog where you will find tutorials on web development and AI integration. Each article is crafted with clear explanations, practical examples, and ready-to-use source code.

Talk to me
Copy email
LinkedIn
GitHub
Dev.to
Privacy Policy