## Definition **Prompt engineering** is the practice of designing the textual inputs to an LLM to elicit useful, reliable, structured outputs. Sits between programming (deterministic, specified) and writing (open-ended, intuitive). The discipline matured as LLMs became central to production systems. ## The Working Premise LLM behaviour is sensitive to: - **Order** of information — see [[Token]]. - **Specificity** of instructions. - **Format** (markdown, XML tags, JSON schema). - **Examples** (zero-shot vs few-shot — see [[In-Context Learning]]). - **Tone and persona** of the prompt. - **Position of intent** — instructions near the end of long prompts work better. Small changes can produce large output changes. This is uncomfortable for engineers used to deterministic interfaces; it is the actual landscape. ## High-Leverage Techniques ### Clear, specific instructions > "Summarise this in three bullet points, each under 15 words." > beats > "Give me a quick summary." ### Structured output requests Ask for JSON, XML tags, or a fixed markdown skeleton. The structure narrows the space of plausible responses. ### Few-shot examples Three exemplars showing input → desired output. The model imitates the format on the unseen query. See [[In-Context Learning]]. ### Chain-of-Thought triggers "Think step by step" — see [[Chain-of-Thought]]. Cheapest reliability upgrade for hard reasoning. ### Role and persona "You are a senior code reviewer evaluating diffs against a spec." Useful when the desired stance is uncommon in pretraining data. ### Constraints over instructions "You may use Read and Grep. You may not call Write or Bash." Constrains the action space; often more effective than describing the persona. ## Anti-Patterns - **Wishful prompts.** "Be accurate and don't hallucinate." Has minimal effect. - **Over-instruction.** Prompts so long the actual task gets lost mid-context (see [[Lost in the Middle Effect]]). - **Politeness inflation.** "Please be very careful and thoughtful and consider all aspects." Costs tokens; rarely helps. - **Ad-hoc iteration without measurement.** "It works on my one example" isn't evidence. ## When Prompt Engineering Stops Mattering When the same prompt is used over and over (CI reviewers, batch jobs), invest in [[Prompt Caching]] and structured evaluation. Prompt engineering then becomes prompt *operations*. ## Relation to System Prompts See [[System Prompt]] — the OS-level layer of prompting; sets standing rules for every turn. ## Related - [[System Prompt]] - [[In-Context Learning]] - [[Chain-of-Thought]] - [[Spec-as-Prompt Pattern]] - [[Prompt Caching]]