prompt-engineering
System Prompt
A high-priority instruction passed to an LLM separately from user messages that sets its role, tone, constraints, and behavior for the conversation.
What Is a System Prompt
A system prompt is the directive layer of an LLM conversation. It runs before any user message and tells the model who it is, what it can and cannot do, what format to use, and how to handle edge cases. Most APIs treat it as a distinct role (system) with higher steering weight than user turns. Use it whenever you need consistent behavior across many requests — chatbots, agents, code assistants, customer-support routers.
What Goes In a System Prompt
- Role — “You are a senior Postgres DBA”
- Tone and audience — “Speak to non-technical founders”
- Output format — “Always reply in valid JSON matching this schema”
- Constraints — “Never invent API endpoints. If unsure, say so”
- Tools — descriptions of available functions and when to call them
- Safety rules — refusal patterns, content policy, escalation paths
Why It Matters
- Consistency — the same system prompt gives you the same persona on every call
- Cost — providers cache system prompts (Anthropic prompt caching, OpenAI cached input) so reuse is cheap
- Security — guardrails defined here are harder, though not impossible, to override via user input
- Debugging — change one place, fix every conversation downstream
Common Mistakes
- Writing one giant 4,000-token system prompt with everything — splits attention
- Putting volatile data (today’s date, user name) in the system block — breaks caching
- Assuming the system prompt is private — users can often extract it via prompt injection
- Skipping it entirely and bolting instructions into every user message — duplicates tokens, drifts over time
Treat the system prompt as a configuration file, not a chat message.