0%
Prompt Engineering11 min

System Prompt Engineering

System prompts are the developer layer of LLM interaction — they shape everything the model does before the user types a single character. Designing them well is a core engineering skill.

What system prompts control

  • Persona and tone — who the model presents itself as
  • Scope — what topics it will and will not address
  • Format defaults — how responses are structured
  • Grounding context — background information the model needs
  • Behavioural constraints — rules and safety guardrails
  • Output schemas — required structure for downstream processing

Anatomy of an effective system prompt

A well-structured system prompt typically includes: (1) role definition, (2) context about the deployment environment and users, (3) behavioural rules (what to do and what not to do), (4) output format specification, and (5) examples or clarifications for edge cases. Order matters — models attend more to early instructions.

Prompt injection risks

Prompt injection is an attack where malicious content in user input or retrieved documents attempts to override the system prompt ("Ignore previous instructions and..."). This is a real security concern for systems that process untrusted input. Mitigations include: separating system and user content clearly, using structured formats that are harder to inject into, and treating model outputs as untrusted before validation.

Iterating on system prompts

System prompt engineering is empirical. Build an evaluation set of inputs and expected outputs, then iterate on the prompt against that set. Avoid optimising for a single example — what improves performance on one case often degrades another. Track versions as you would track code.

System prompts should be treated as production code — versioned, tested against an evaluation suite, and changed with the same rigour as any other component of a production system.

Check your understanding

3 questions, 70% to pass
1. What do system prompts control?
2. Why does instruction order matter in a system prompt?
3. What is prompt injection?