A large language model’s output quality depends enormously on input quality. The same model with a carefully designed prompt produces precise, useful results; with a vague prompt, it produces generic, off-target, or incorrect outputs. Prompt engineering is the systematic practice of designing and optimizing prompts to get the best possible outputs from LLMs.
## Foundational Techniques
**Zero-shot prompting**: state the task directly without examples. Works well for common tasks the model was extensively trained on.
**Few-shot prompting**: provide 2–5 input-output examples in the prompt to demonstrate the expected format and style. Particularly effective for tasks with specific output formats or domain-specific conventions.
**Role prompting**: assign the model a persona (“You are a senior securities lawyer” / “You are a quantum physics professor”). The role primes relevant knowledge and communication style.
**System prompts**: set behavioral rules, knowledge constraints, and output format requirements before the conversation begins. This is the primary configuration mechanism when building AI applications.
## Reasoning Prompts
**Chain-of-thought (CoT)**: ask the model to show its reasoning step by step (“Let’s think through this carefully, step by step”). Consistently improves accuracy on math, logic, and multi-step decision problems. Even the phrase “Let’s think step by step” — a zero-shot CoT trigger — measurably helps.
**Self-consistency**: generate multiple independent reasoning chains for the same problem and take the most frequent answer. Reduces single-chain reasoning errors. Computationally expensive but valuable for high-stakes tasks.
**Tree of Thoughts (ToT)**: have the model simultaneously explore multiple solution paths, evaluate each, and continue the most promising. Effective for complex open-ended problems; higher compute cost than standard CoT.
**ReAct (Reasoning + Acting)**: alternates between reasoning steps (“I need to search for X to answer this”) and action steps (actually calling the search tool). The core prompting pattern for AI agent workflows.
## Structured Output
Getting reliable structured output (JSON, tables, specific document formats) requires deliberate prompt design:
– Specify the exact JSON schema or show an example in the prompt
– Ask the model to confirm its understanding before outputting (reduces format errors)
– Use XML tags to delimit sections (Claude responds particularly well to this)
– Use tool calling with a defined schema for production use (more reliable than prompting alone)
## Optimization Strategies
**Specificity matters**: “write an article about quantum computing” is less effective than “write an 800-word article for Python developers with 3 years of experience explaining quantum superposition, with a code analogy and two concrete examples.”
**Negative constraints**: specifying what you don’t want (“avoid marketing language,” “don’t use jargon”) is as important as specifying what you do want.
**Task decomposition**: breaking complex tasks into sequential subtasks and prompting for each separately, then integrating results, outperforms single complex prompts.
**DSPy** (Stanford): a framework for programmatic prompt optimization, using LLMs to improve the prompts themselves by observing output quality. See [DSPy on GitHub](https://github.com/stanfordnlp/dspy).
Anthropic’s official prompt engineering guide is among the most thorough available: [Anthropic Prompt Engineering](https://docs.anthropic.com/claude/docs/prompt-engineering). For practical examples, see [AI Tools Practical Guide](https://sunqi.org/ai-tools-practical-tips-en/).
—




