Prompt Engineering: From Zero to Reliable Outputs
Prompt engineering is the single most leveraged skill in LLM work. A great prompt beats a great model 80% of the time.
Levels of prompting
Level 1: Zero-shot
response = llm("Translate to French: Hello world")
Level 2: Few-shot (give examples)
prompt = """Translate English to French:
English: Hello
French: Bonjour
English: Goodbye
French: Au revoir
English: Thank you
French:"""
response = llm(prompt)
Level 3: System + Instructions
messages = [
{"role": "system", "content": "You are a professional translator. Always output in the target language only, no explanations."},
{"role": "user", "content": "Thank you"}
]
Level 4: Chain-of-thought (CoT)
prompt = """Solve step by step.
Q: A store sells 3 shirts at $15 each and 2 pants at $25 each. What's the total?
A: Let me calculate:
- Shirts: 3 × $15 = $45
- Pants: 2 × $25 = $50
- Total: $45 + $50 = $95
Q: 5 books at $12 each and 3 pens at $4 each. Total?
A:"""
Level 5: Structured output
import json
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "List 3 fruits with their colors"}],
response_format={"type": "json_object"}
)
data = json.loads(response.choices[0].message.content)
# {"fruits": [{"name": "apple", "color": "red"}, ...]}
The 5 principles
- Be specific — “Write a 100-word summary” > “Summarize”
- Give examples — show, don’t tell
- Use delimiters —
"""..."""or XML tags - Specify format — “Output as JSON with keys: …”
- Chain-of-thought — for reasoning tasks
The “garbage in, garbage out” rule
Bad: “Write a story” Good: “Write a 500-word cyberpunk story set in 2099 Tokyo, featuring a hacker named Mira. Style: dark, fast-paced, sensory. End on a twist.”
Key takeaways
- 80% of LLM success = prompt quality
- Few-shot > zero-shot for most tasks
- Always specify output format