Prompt Engineering

The practice of crafting, structuring, and iterating on inputs to large language models to reliably elicit desired outputs — combining clarity, context, examples, and constraints.

Prompt engineering is the discipline of communicating effectively with large language models. Because LLMs are trained to predict plausible continuations of text, how you frame a request has an enormous impact on what you get back — the same underlying model can behave like an expert assistant or produce generic noise depending on prompt quality.

Foundational Techniques

Zero-Shot Prompting

Ask the model directly with no examples. Works for tasks the model has seen frequently in training: summarization, translation, common classification tasks. Breaks down for specialized, ambiguous, or novel tasks.

Few-Shot Prompting

Provide 2–10 examples of input→output pairs before the real query. Dramatically improves consistency for formatting, tone, and domain-specific tasks. The examples function as in-context training.

Chain-of-Thought (CoT)

Ask the model to "think step by step" before giving an answer. Adds intermediate reasoning steps that improve accuracy on math, logic, and multi-step problems. "Let's think step by step" is one of the highest-ROI prompt additions for reasoning tasks.

Role Prompting

Assign an expert persona: "You are a senior security engineer reviewing code for vulnerabilities." This activates relevant knowledge and sets the expected tone and depth.

Structured Output

Request JSON, markdown tables, or specific formats. Pair with model-native JSON mode (supported by most API providers) for reliable parsing in downstream code.

System Prompts

In chat-based APIs, the System Prompt is separate from the user turn — it persists across the conversation and sets persistent instructions. Well-written system prompts include: persona, capabilities, constraints, output format, and relevant context.

Prompt Engineering in AI Tooling

AI editors like Cursor and Windsurf let you define project-level rules that become part of the system prompt. Langchain uses prompt templates to parameterize prompts. Mcp Model Context Protocol exposes "prompts" as a primitive that servers can serve to clients.

Common Pitfalls

  • Vague instructions — "write a summary" vs "write a 3-sentence summary for a non-technical audience"
  • No output format — model invents format; downstream parsing fails
  • Prompt injection — untrusted user input that overrides your instructions
  • Context bloat — stuffing too much irrelevant context wastes the context window and degrades focus

Subscribe to Sahil's Playbook

Clear thinking on product, engineering, and building at scale. No noise. One email when there's something worth sharing.
[email protected]
Subscribe
Mastodon