Prompting and structured output

5 concepts · 10 practice questions

Anatomy of a production prompt

A production prompt has parts with different jobs. The system prompt holds what stays the same: the role, the task, the rules and the output format. The user turn holds what changes per request: the input and any retrieved context, fenced in tags so the model can tell data from instructions. Say what to do when the input does not fit the task, and describe good output instead of listing only what to avoid. Keep the fixed part first and identical across requests, so the provider's prompt cache can reuse it.

SYSTEM = """You classify support tickets for Acme.
Labels: billing, bug, account, other.
Use other when the ticket fits none of them. Never invent a label.
Reply with JSON only: {"label": "...", "reason": "..."}"""

def build(ticket_text):
    user = f"<ticket>\n{ticket_text}\n</ticket>\nClassify the ticket above."
    return [{"role": "system", "content": SYSTEM},
            {"role": "user", "content": user}]

Also covered

Few-shot examples
Schemas and validation
Sampling settings in practice
Prompts as versioned code

Sign in to read the rest and take the 10-question test.

Sign in to continue