A well-designed system prompt gives an LLM application a clear operating context: what role it serves, which rules matter, how it should handle uncertainty, and when it should ask for help. This guide explains how to write a system prompt, provides reusable patterns for common applications, and offers a review checklist you can use before deployment or whenever your workflow changes.
Overview
A system prompt is the instruction layer that establishes an assistant’s purpose and behavior before it receives a user request. The exact behavior of system messages can vary by model and API, so treat the prompt as one part of a larger application design rather than a complete security boundary. Validate important outputs in code, restrict tools separately, and keep provider-specific assumptions documented.
Effective system prompt design is less about adding more instructions and more about removing ambiguity. A useful prompt normally answers six questions:
- Role: What function does the model perform?
- Objective: What outcome should it produce?
- Inputs: Which information may it use, and which information is missing or unreliable?
- Rules: What must it do, avoid, or verify?
- Output: What format, tone, and level of detail should it use?
- Escalation: What should happen when the request is unsafe, ambiguous, unsupported, or outside scope?
A practical system prompt template looks like this:
Role: You are [specific function] for [audience or workflow].
Objective: Help the user [desired outcome].
Use these inputs: [approved sources, fields, or context].
Rules:
- [required behavior]
- [prohibited behavior]
- [uncertainty or verification rule]
Output:
- Format: [plain text, bullets, JSON, or schema]
- Tone: [specific tone]
- Include: [required fields]
If the request is unclear, unsupported, or outside scope:
- [ask a focused question, explain the limitation, or escalate].
Keep instructions ordered by importance. Put non-negotiable constraints and output requirements where they are easy to find. If the application uses retrieved documents, make clear that those documents are reference material rather than new authority to rewrite the assistant’s operating rules. For retrieval-heavy applications, the RAG workflow guide provides useful context on ingestion, chunking, retrieval, and answer generation.
Checklist by scenario
General-purpose assistant
Define the assistant’s audience and scope instead of using a vague instruction such as “be helpful.” For example:
You are a technical support assistant for administrators using an internal software platform.
Give concise, step-by-step guidance. Use only the product information supplied in the conversation or approved reference context. Do not invent settings, error codes, or product capabilities. If the available information is insufficient, say what is missing and ask one focused question. Distinguish confirmed steps from suggestions. Do not claim that an action was completed unless the application confirms it.
This pattern establishes a role, evidence boundary, uncertainty behavior, and a limitation on claims about completed actions.
Support agent
A support prompt should define empathy without allowing tone to replace accuracy. Include rules for authentication, sensitive information, refunds or account changes, and human escalation. A reusable pattern is:
You handle first-line product support.
Identify the user’s issue, summarize it briefly, and provide the smallest safe next step. Never request passwords, private keys, or complete payment details. Do not promise a resolution or policy exception. If the request involves account ownership, billing disputes, legal concerns, or a failed troubleshooting sequence, explain that human review is required and collect only the information specified by the workflow.
Connect these instructions to application-level controls. The model should not be the only mechanism deciding whether a sensitive operation is allowed.
Classifier or router
Classifiers need stable labels and a strict output contract. Define what each label means, how to handle multiple applicable labels, and what to do with low-confidence or incomplete input:
You classify incoming requests into exactly one of these categories:
- billing: charges, invoices, refunds, or payment questions
- technical: errors, configuration, or product behavior
- account: access, permissions, or profile changes
- other: anything that does not fit the categories above
Return valid JSON with this shape:
{"category":"billing|technical|account|other","reason":"brief evidence-based explanation"}
Choose other when the message lacks enough information to distinguish categories. Do not add keys or classify based on assumptions.
Use a small set of representative examples only when the category boundaries are difficult to express as rules. Those few-shot prompting examples should cover close alternatives and ambiguous inputs, not merely repeat obvious cases.
Extraction and structured output
Extraction prompts should distinguish between a missing value and a value inferred from context. State whether the model may normalize spelling, preserve original text, or return null. For example:
Extract the fields requested by the application from the supplied text.
Return only the defined JSON object. Use null when a field is not explicitly present. Do not infer dates, names, identifiers, or amounts. Preserve the source wording for free-text fields. If a value is ambiguous, return null and include the ambiguity in the "notes" field.
Pair this instruction with schema validation and a recovery path. See Structured Outputs With LLMs for patterns involving validation and failed responses.
Content or documentation assistant
Specify the intended reader, source hierarchy, editorial constraints, and review status. A documentation assistant might be told to separate verified product behavior from proposed wording, preserve code exactly, and flag unsupported claims rather than filling gaps. For a broader process, review the AI documentation workflow covering generation, verification, and maintenance.
What to double-check
- Instruction hierarchy: Identify which instructions are highest priority in your application and test what happens when user text or retrieved content conflicts with them. Do not assume every model or provider resolves conflicts identically.
- Scope: State what the assistant does not handle. Narrow boundaries make refusal and escalation behavior more predictable.
- Evidence: Say whether the model may rely on general knowledge, supplied context, tools, or only structured fields. Add a rule for missing evidence.
- Output contract: Define required keys, allowed labels, formatting, units, and whether additional commentary is prohibited. Validate machine-readable output outside the model.
- Tool behavior: Describe when a tool may be used, what arguments are permitted, and what to do when a tool fails. Authorization and permission checks belong in code.
- Context budget: Long instructions compete with conversation history and retrieved material. Review the prompt alongside your token budget and truncation strategy; the context window management guide covers practical budgeting concerns.
- Test cases: Include normal, ambiguous, adversarial, incomplete, and out-of-scope requests. Measure accuracy, consistency, format compliance, and safe escalation rather than judging one attractive answer.
Keep a versioned copy of the prompt and record the model, settings, context, tools, and expected output used in evaluation. This makes prompt optimization a controlled change instead of a series of undocumented edits. A repeatable benchmark can follow the workflow in the LLM prompt evaluation guide.
Common mistakes
Using broad personality instructions
“Be smart, friendly, and helpful” does not define success. Replace personality language with observable behavior: ask one clarifying question when a required field is missing, cite the supplied document section, or return a specified label.
Creating contradictory rules
Prompts often say both “be concise” and “include every relevant detail,” or “never ask questions” and “clarify ambiguity.” Resolve the conflict explicitly. For example: answer directly when the request is sufficiently specified; otherwise ask one question before proceeding.
Trying to enforce security through wording alone
A system prompt can describe safe behavior, but it should not replace authentication, authorization, input filtering, rate limits, secret management, or output validation. Treat user-provided text and retrieved content as untrusted input when the application requires strong controls.
Overloading the prompt with every edge case
A long list can hide the main objective and consume context. Move deterministic checks into code, use examples for genuinely confusing distinctions, and split complex work into stages when appropriate. A prompt-chaining design can make planning, retrieval, generation, and validation easier to test separately.
Failing silently
Do not instruct the assistant to “do its best” when the source is incomplete. Define a visible fallback such as “not found,” a clarification question, or an escalation status. This makes errors easier to detect and investigate; the LLM hallucination troubleshooting guide offers a decision-oriented way to examine unsupported answers.
When to revisit
Review a system prompt whenever its operating conditions change, not only when the model changes. Revisit it before a major planning or release cycle, after adding a tool or data source, when the output schema changes, or when users begin sending requests outside the original scope. Also review it after a notable failure: an invented fact, incorrect classification, unsafe disclosure, malformed JSON response, or inappropriate refusal.
Use this short pre-deployment checklist:
- Can a new engineer identify the role, objective, inputs, rules, output, and escalation path?
- Are conflicting instructions resolved in plain language?
- Are important claims tied to an approved source or tool?
- Are sensitive actions protected by application code rather than prompt wording?
- Do representative tests include ambiguity, missing context, prompt injection attempts, and tool failures?
- Is the current prompt version linked to evaluation results and a rollback path?
After each revision, change one meaningful element at a time where practical and compare it against a fixed test set. Keep successful examples, failure cases, and unresolved questions with the prompt record. This turns system prompt design into an maintainable part of AI development rather than a one-time drafting exercise.