Learn
Learn hubFoundationsPromptingSQL & dataVisualizationRAGChatbotsPrototypesAgents & launch FAANG prep
Weekly practice
0102030405060708091011121314

Prompting

Chapter 2 · Phase 1 · practice in Week 2 and Week 3

What you will know after this chapter
How a prompt is structured (system / user / assistant) · the six core prompting patterns · how to design evals before writing prompts · how function calling works and when to use it · how to version prompts like code

1. Anatomy of a prompt

Modern LLMs use a chat format with three distinct message roles. Understanding them is the foundation of everything else.

Chat message roles
system
You are a triage assistant for a B2B SaaS support team. Answer only from the provided knowledge base. If unsure, say "I don't know" and offer to escalate.
user
How do I export my data to CSV?
assistant
To export your data: go to Settings → Data → Export. Select CSV format. [Source: KB article #0042]
System message
Persistent instructions that frame the model's role, constraints, and behavior. Set once per session. This is where PM requirements live: persona, output format, scope limits, escalation rules.
User message
The human turn in the conversation. In production, this is what your user types — or what your application constructs programmatically (e.g., a retrieved document + user question).
Assistant message
The model's response. In multi-turn conversations, previous assistant turns are included in subsequent calls to maintain context — consuming tokens each time.

2. Core prompting patterns

Pattern 1 — Role + constraint

Give the model a specific role and explicit boundaries. This is the minimum viable system prompt.

You are a senior TPM reviewing engineering estimates.
Your job: identify unstated assumptions and missing dependencies.
DO NOT provide your own estimate. Ask clarifying questions only.
Respond in bullet points, max 5.
Why it works
Without a role, models give generic responses. A role + explicit constraint (what not to do) drastically narrows the output space and reduces hallucination.

Pattern 2 — Few-shot examples

Show 2–5 examples of input → desired output in the prompt. The model learns the pattern without training.

Classify each support ticket as: billing / technical / feature-request

Ticket: "My invoice shows double charge this month"
Category: billing

Ticket: "The API returns 500 when I POST with a null field"
Category: technical

Ticket: "Can you add dark mode?"
Category: feature-request

Ticket: "I was charged twice for the Pro plan"
Category:
PM tip
Few-shot is your fastest path to consistent output format and category alignment. Start with 3 examples. If accuracy is poor, add more examples or add a negative example ("here is what NOT to do").

Pattern 3 — Chain-of-thought (CoT)

Ask the model to reason step by step before giving an answer. This dramatically improves accuracy on complex or multi-step tasks.

Analyze this incident and identify the root cause.
Think step by step:
1. What symptoms are described?
2. What is the likely proximate cause?
3. What is the systemic cause?
4. What mitigations would prevent recurrence?

Incident: [paste incident report]
Why it works
CoT forces the model to "show its work." Each reasoning step becomes context for the next, reducing errors that happen when the model jumps to a conclusion. Accuracy on math, logic, and diagnosis tasks improves significantly.

Pattern 4 — Self-critique

After an initial response, ask the model to review its own output for errors, gaps, or risky claims.

# Step 1 — Generate
Generate a go-to-market plan for [product].

# Step 2 — Critique (new message)
Review the plan above. List:
- Any assumptions that need validation
- Any claims that might be factually wrong
- Any risks not mentioned
Be specific.

Pattern 5 — Decomposition

Break a complex task into explicit sub-tasks and ask the model to complete each step before moving to the next.

Task: Write a technical spec for a rate-limiting feature.

Step 1: List all user stories this feature must satisfy.
Step 2: Define the data model needed.
Step 3: Define the API contract.
Step 4: Identify failure modes and mitigations.

Complete Step 1 first, then wait for my confirmation before Step 2.

Pattern 6 — Constrained output format

Specify the exact output structure (JSON, YAML, a table, specific headings). This is essential for production systems that parse the response programmatically.

Return your analysis as JSON with this schema:
{
  "severity": "P0" | "P1" | "P2" | "P3",
  "category": string,
  "summary": string (max 50 chars),
  "recommended_action": string,
  "confidence": 0.0–1.0
}
Return only the JSON. No explanation text.

3. Evaluations (evals) — design before you write prompts

An eval is a test suite for a prompt. Before writing a single line of prompt text, define what "good" looks like and how you will measure it. This is the PM's highest-leverage contribution to an AI feature.

Eval
A set of (input, expected output) or (input, scoring criteria) pairs used to measure prompt quality at scale. Like unit tests, but for language model behavior.

Types of evals

1

Exact match

Output must equal or contain a specific string. Good for classification, routing, structured output. "category" === "billing"

2

Contains check

Output must include certain phrases or citations. Good for grounded responses. response.includes("KB article #0042")

3

LLM-as-judge

A second LLM call scores the response on criteria like helpfulness, safety, and accuracy. Good for open-ended text where exact match is too strict. Return a 1–5 score with a rationale.

4

Human eval

Domain expert reviews a sample of outputs and rates them. Gold standard but expensive. Use for final validation and to create training data for LLM-as-judge.

PM anti-pattern
Writing a prompt, seeing it "looks good" on 3 examples, and shipping. Without evals on 50–100 representative cases, you have no idea how your prompt behaves on edge cases, adversarial inputs, or off-topic queries. Build evals first.

4. Function calling (tool use)

Modern LLMs can decide to call external functions and use their results before generating a response. This is how you ground a model in live data without RAG.

Function calling flow
User: "What is the current status of incident INC-4821?"
LLM decides: call get_incident(id="INC-4821")
Your code executes the function → returns live data
LLM generates response grounded in live incident data

Functions are defined as JSON schemas passed to the API. The model does not execute code — it generates a structured call that your application executes.

tools = [{
  "type": "function",
  "function": {
    "name": "get_incident",
    "description": "Fetch live incident status from PagerDuty",
    "parameters": {
      "type": "object",
      "properties": {
        "id": {"type": "string", "description": "Incident ID, e.g. INC-4821"}
      },
      "required": ["id"]
    }
  }
}]

5. Prompt versioning and governance

Production prompts are code. A prompt change can break features just as badly as a code change.

Store prompts in version control

Check prompts into your Git repo. Every change has a PR, a diff, and a reviewer. Never edit prompts directly in production.

Run evals on every prompt change

Before merging a prompt update, run your eval suite and compare scores. A prompt that improves one metric may regress another.

Pin model versions

Model providers update underlying models. A prompt written for gpt-4o-2024-08-06 may behave differently on gpt-4o-2025-01-01. Pin the exact model version in production and upgrade deliberately.

Log every prompt + response

Log the full prompt (including system message), model version, temperature, and response for every production call. You need this for debugging, retraining, and incident investigation.


← Foundations
Practice → Week 2 Next: SQL & data →

Test your understanding

What are the four main components of a well-structured prompt?v
Role (who the model is), Context (relevant background), Task (what to do, precisely), Format (how to structure output). Adding examples (few-shot) is a powerful fifth component.
What is chain-of-thought prompting, and when does it improve output quality?v
Chain-of-thought asks the model to reason step-by-step before answering ('think through this step by step'). Improves quality on multi-step reasoning, math, logic, and complex analysis. Little benefit on simple factual lookups; increases token cost.
You have 3 examples to include in a prompt. What makes a good few-shot example?v
Good examples: (1) representative of the full input distribution, not just easy cases; (2) cover edge cases you care about; (3) demonstrate the exact output format you expect; (4) are internally consistent. Contradictory examples confuse the model more than no examples.
A prompt works great in development but fails on edge-case inputs in production. What is your first debugging step?v
Sample and categorize 20 real failing cases. Find the pattern — is it one query type, one user segment, a specific phrasing? Pick the most common failure mode and fix that first by adding a targeted example or constraint.
What is function/tool calling, and how does it differ from asking for JSON output?v
Tool calling is a first-class API feature where you declare functions the model can invoke. It is more reliable than requesting JSON because the API enforces the schema and the model is specifically trained to produce valid tool calls, not free-form text.
Write a role constraint in a system prompt that limits a support bot to billing questions only.v
'You are a billing support assistant. Only answer questions about invoices, payments, plan upgrades, and account charges. If asked about anything else, politely say you can only help with billing and suggest contacting the appropriate team.'
What is a 'self-critique' prompt pattern, and when is it useful?v
Ask the model to review its own output: 'Review your previous answer. Is anything incorrect or unsupported? If so, revise it.' Useful when quality matters more than latency and you can afford an extra LLM call. Less useful on simple tasks.

Further reading & watching