Prompt Fundamentals
Anatomy of a Prompt
Break down the key components of an effective prompt: context, instruction, examples, and format.
The Five Components of an Effective Prompt
1. Role / Persona
Tell the AI who it is or how it should behave. This "primes" the model for a specific type of output.
2. Context / Background
Provide relevant background information. The more context you give, the more tailored the response.
3. Task / Instruction
Clear, specific instruction of what you want done. Use action verbs: "Analyze", "Generate", "Compare", "Rewrite".
4. Input Data
The actual content to work with — enclosed in delimiters like triple quotes, XML tags, or markdown code blocks.
5. Output Format
Specify exactly how you want the response — JSON, bullet list, table, numbered list, specific length, etc.
Using XML Tags for Structure
Claude and many other models respond well to XML-style tags for organizing different parts of your prompt:
<context>background info</context>
<task>what to do</task>
<data>content to process</data>
<format>how to respond</format>
Delimiters for Input Data
Always wrap input data in clear delimiters to prevent injection and confusion:
- Triple quotes:
""" - XML tags:
<article>.....</article> - Code fences: ```
Example
// Full example with all components:
"""
<role>
You are a senior software engineer with expertise in
Python and system design, writing for intermediate developers.
</role>
<context>
I'm building a task queue system for a web application.
I need to process user-uploaded images asynchronously.
Technology stack: Python, FastAPI, Redis.
</context>
<task>
Review the following code and:
1. Identify any bugs or anti-patterns
2. Suggest 2-3 specific improvements
3. Provide a refactored version with your improvements
</task>
<code>
def process_image(image_path):
img = Image.open(image_path)
img = img.resize((800, 600))
img.save(image_path)
return "done"
</code>
<format>
Structure your response as:
## Issues Found
[List issues with severity: Critical/Major/Minor]
## Improvements
[Numbered list of specific improvements]
## Refactored Code
[Python code block with comments]
</format>
"""