ModelRefs / Prompt Engineering — Tutorial

Prompt Engineering — Tutorial

Write instructions that reliably get LLMs to do what you want. Covers Instructions are your API contract, Zero-shot, few-shot, and chain-of-thought.

Overview

Write instructions that reliably get LLMs to do what you want

Level: Intermediate. Estimated reading time: 30 minutes.

Instructions are your API contract

Prompt engineering is the practice of crafting inputs to language models to reliably elicit desired outputs. Unlike traditional software where you write code, with LLMs you write natural language specifications — and the model interprets them.

The key insight: LLMs are extremely capable but literal. They do exactly what you describe, not what you mean. If your output is inconsistent, the problem is almost always ambiguity in the prompt, not a fundamental model limitation.

Zero-shot, few-shot, and chain-of-thought

Zero-shot: just give the instruction. Works for simple, well-defined tasks. "Classify this review as positive or negative."

Few-shot: provide 2-5 examples before the task. Dramatically improves consistency for format-sensitive outputs and rare task types. "Here are 3 examples of the format I want... Now do this one."

Chain-of-thought (CoT): add "Think step by step" or include reasoning in examples. Forces the model to externalise intermediate steps — dramatically improves math, logic, and multi-step reasoning. o1/o3 models do extended CoT internally; for other models, prompt for it explicitly.

System prompts, roles, and structured output

System prompt: persistent instructions that apply to the whole conversation. Use for: persona, format constraints, safety rules, tool descriptions.

Structured output: ask for JSON, XML, or a specific schema to make parsing reliable. Combine with json_mode=True (OpenAI) or tool use (Anthropic) for guaranteed-valid JSON.

Common patterns that improve reliability: • State the output format explicitly ("Return JSON with keys: name, score, reason") • Constrain the answer space ("Answer with exactly one word: positive, negative, or neutral") • Tell the model what NOT to do (negative instructions are often more reliable than positive) • Add XML tags: <task>...</task> to separate instructions from user content

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Prompt Engineering — Tutorial.