💚
Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Prompt Structure
A well-structured prompt has four key components: context, instruction, example (optional), and desired output format. Not every prompt needs all four, but knowing this structure helps you build effective prompts systematically.
10 min•By Priygop Team•Updated 2026
The Four Components of a Strong Prompt
- Context: background information the AI needs to understand your situation
- Instruction: the specific task you want the AI to do
- Example (optional): a sample of the output you want, to show the AI what you mean
- Output format: how you want the response structured (list, table, paragraph, JSON)
A Prompt with All Four Components
A Prompt with All Four Components
# Prompt structure example
prompt_components = {
"context": """I am a high school teacher preparing a lesson on climate change
for 15-year-old students. The students have basic science knowledge
but have never studied environmental science before.""",
"instruction": """Explain the greenhouse effect in simple terms that
a 15-year-old can understand. Avoid complex scientific terminology.""",
"example": """Example of the style I want:
'The ozone layer is like a sunscreen for Earth.
Just as sunscreen stops ultraviolet rays from burning your skin,
the ozone layer stops harmful radiation from reaching the ground.'
Use a similar everyday analogy in your explanation.""",
"output_format": """Format the explanation as:
1. A one-sentence simple definition
2. A real-world analogy (2-3 sentences)
3. Three key effects in bullet points"""
}
# Combine into a full prompt
full_prompt = f"""
{prompt_components['context']}
{prompt_components['instruction']}
{prompt_components['example']}
{prompt_components['output_format']}
"""
print("Full prompt structure:")
for key, value in prompt_components.items():
print(f"\n[{key.upper()}]")
print(value[:100] + "..." if len(value) > 100 else value)Diagram
Loading diagram…
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Key Takeaways
- A well-structured prompt has four key components: context, instruction, example (optional), and desired output format.
- Context: background information the AI needs to understand your situation
- Instruction: the specific task you want the AI to do
- Example (optional): a sample of the output you want, to show the AI what you mean