Prompt Engineering
The craft of getting reliable, high-quality outputs from AI models.
Prompts are the interface between what you want and what the model does. A well-crafted prompt can turn a cheap model into a great product. A lazy prompt will waste the most expensive model on earth.
The anatomy of a prompt
| Component | What it does | Example |
|---|---|---|
| System prompt | Sets persona, constraints, behavioral rules | “You are a senior tax advisor. Never give advice without citing the relevant tax code.” |
| Context | Background information the model needs | The user's financial data, relevant regulations |
| Instruction | The actual task | “Analyze this return and identify the three highest-risk deductions.” |
| Examples | Demonstrations of desired input/output | Two or three sample analyses |
| Output format | How to structure the response | “Respond in JSON with fields: deduction, risk_level, explanation.” |
Three strategies that cover 90% of use cases
Zero-shot prompting. Give the model an instruction with no examples. Works for simple, well-defined tasks. The advantage is simplicity. The disadvantage is inconsistent formatting.
Few-shot prompting. Provide 2-5 examples before your actual query. Use this when you need specific output formats or domain-specific terminology. Three to five examples is usually enough.
Chain of Thought (CoT). Ask the model to reason step by step before giving its final answer. This dramatically improves performance on math, multi-step reasoning, and complex analysis.
As a rough guide: zero-shot gets you about 60% reliability, few-shot pushes that to 80%, and chain of thought reaches 90% or higher.
System prompts: where your product lives
The system prompt is the single most important piece of text in your entire application. An effective system prompt covers four things:
- Identity. Who or what is the assistant?
- Constraints. What should the model NOT do?
- Behavior. How should it interact?
- Format. How should responses be structured?
Version control your prompts. Treat them like code. Track which version produced which outputs. A “small tweak” to a system prompt can change behavior in ways you don't expect.
Getting structured output
For production systems, you almost always need the model to return data in a specific format. Three approaches: JSON mode (most APIs support forcing valid JSON), Function calling / tool use (define schemas the model must follow), and Structured output libraries (like Instructor for Python).
Prompt injection: the security risk you cannot ignore
When your prompts include user input, you're at risk of prompt injection. There is no perfect defense, but effective mitigations include: delimiters, instruction hierarchy, output filtering, and least privilege.
Test your prompts systematically. Build an eval set covering the happy path, edge cases, and adversarial inputs. Track accuracy, consistency, latency, and token usage.
System Prompt Architect
Writes and pressure-tests your AI product's system prompt.
---
description: Design, write, and pressure-test a system prompt for your AI product feature.
---
You are a system prompt architect. The user is building an AI product feature and needs a production-grade system prompt.
Ask: "What does this AI feature do, and who uses it? Be specific."
Then build through four layers: 1. Identity, 2. Constraints, 3. Behavior, 4. Output format.
After writing the prompt, run three stress tests:
1. An adversarial input
2. An edge case
3. A request outside scope
End with: "Version control this prompt. Treat changes like code changes."
Reference: https://builderspath.dev/playbook/#prompt-engineering