How to Write System Prompts: A Practical Framework With Reusable Examples
system promptsprompt designLLMsAI developmentprompt templates

How to Write System Prompts: A Practical Framework With Reusable Examples

PPrompt Forge Editorial Team
2026-11-27
7 min read

Learn how to write reliable system prompts with reusable templates, tool rules, output schemas, refusal guidance, and testing checklists.

A reliable system prompt gives an AI application a stable operating framework: what the model should do, how it should respond, when it should use tools, and what it must not assume. This practical system prompt tutorial provides a reusable framework, examples, review checklist, and testing process for building prompts that are easier to maintain across models, workflows, and product changes.

Overview

A system prompt is the set of high-level instructions that establishes an assistant’s behavior before it receives a user request. Depending on the platform, it may be called a system message, developer instruction, or another priority-level instruction. The exact instruction hierarchy varies by API and product, so treat the prompt as one part of the application rather than a complete security boundary.

The strongest system prompts are specific without trying to predict every possible conversation. They define the assistant’s purpose, provide decision rules, describe the expected output, and identify situations that require clarification or refusal. They also separate stable behavior from changing data. Product policies, account information, current prices, and other variable inputs generally belong in controlled application context or tools rather than being hard-coded into a prompt.

A reusable system prompt template

Role and purpose:
You are [assistant role]. Your objective is to [specific outcome] for [audience].

Scope:
You can help with [supported tasks]. You should not provide [out-of-scope tasks].

Operating rules:
- Use only the information provided in the conversation, approved context, or available tools.
- If required information is missing, ask a focused clarifying question.
- Distinguish confirmed information from assumptions.
- Follow the requested tone and audience level.

Tool behavior:
- Use [tool] when [condition].
- Do not claim that a tool was used unless it actually was.
- Summarize relevant tool results before giving a recommendation.

Safety and refusal behavior:
- Decline [specific unsafe or unauthorized requests] briefly.
- Offer a safe alternative when one is available.

Output format:
Return [format, sections, fields, or schema].

Quality check:
Before responding, verify that the answer is relevant, complete, and consistent with the output requirements.

Use the template as a design aid, not a script that must be copied unchanged. Remove instructions that do not affect behavior. A short prompt with clear priorities is often easier to test than a long prompt containing overlapping rules.

Checklist by scenario

For a general-purpose assistant

  • Define the job: State whether the assistant is answering questions, drafting content, summarizing documents, troubleshooting software, or performing another defined task.
  • Name the audience: Specify whether responses are intended for developers, customers, analysts, administrators, or another group.
  • Set the communication style: Give observable guidance such as “lead with the answer,” “use numbered steps,” or “explain technical terms on first use.” Avoid vague instructions such as “be excellent.”
  • Handle uncertainty: Tell the assistant to identify missing information, qualify uncertain claims, and avoid presenting guesses as verified facts.
  • Set boundaries: List the tasks that are outside the assistant’s scope and explain what it should do instead.

For a document question-answering or RAG workflow

  • Define the evidence rule: Instruct the model to answer from the supplied documents or retrieved passages and to say when the evidence is insufficient.
  • Preserve citations: Specify the citation format, source identifier, or page reference expected by the application.
  • Separate evidence from interpretation: Ask for a direct answer first, followed by supporting passages or a clearly labeled interpretation.
  • Handle conflicting sources: Require the assistant to identify disagreements rather than silently combining them.
  • Test retrieval edge cases: Include empty results, irrelevant passages, duplicate passages, and documents with conflicting dates or versions.

For a deeper workflow, see this guide to AI document summarization, chunking, citations, and fact checks.

For an AI coding assistant

  • State the repository context: Identify the language, framework, package manager, test command, and style conventions when they are known.
  • Require minimal changes: Tell the assistant to preserve existing behavior and modify only the files or functions needed for the request.
  • Ask for verification: Require tests, linting, type checks, or a clear statement of what could not be run.
  • Protect sensitive material: Instruct the assistant not to expose secrets, credentials, private tokens, or unrelated private files.
  • Make assumptions visible: Ask for a short list of assumptions before a large or potentially destructive change.

When comparing coding workflows, review both model behavior and the surrounding IDE, privacy, and testing controls in a comparison of AI coding assistants.

For a tool-using agent

  • Describe each tool: Explain its purpose, required inputs, expected output, and limitations.
  • Set invocation conditions: Define when a tool is required, optional, or prohibited.
  • Require confirmation for consequential actions: Sending messages, changing records, deleting data, or making purchases should use an explicit approval step where appropriate.
  • Prevent fabricated actions: Tell the assistant to report tool errors and never claim that an action succeeded without a successful result.
  • Define stopping conditions: Specify when the agent should stop, ask for help, or return a partial result.

Tool rules should be supported by application controls. The AI agent architecture guide covers tools, memory, and human approval as separate design concerns.

What to double-check

Instruction priority and conflicts

Review every rule for conflicts. “Be concise” may conflict with “include all reasoning,” while “never ask questions” may conflict with “request missing information.” Decide which instruction wins and state the priority directly. Do not assume that repeating a rule makes it stronger. Your application’s instruction hierarchy and the provider’s implementation determine how messages are handled.

Output schemas

If the application parses the response, specify a precise structure. Name required fields, allowed values, and how to represent unknown or empty values. For production workflows, validate the response outside the model before using it. A system prompt can request valid JSON, but application-level parsing and validation should decide whether the result is acceptable. Use this prompt-to-JSON workflow guide for schema and repair patterns.

Context, limits, and cost

A prompt that works with a short input may fail when conversation history, retrieved documents, or tool results grow. Check the model’s context limits, output limits, input types, and rate behavior for the specific integration. These details can change by model and provider, so keep them in configuration and verify them before deployment. The AI model limits comparison is useful when reviewing these constraints.

Security and untrusted content

Retrieved documents, web pages, uploaded files, and user text may contain instructions that conflict with your application’s goals. Label untrusted content clearly and tell the model to treat it as data rather than authority. Do not rely on a system prompt alone to protect sensitive operations. Use permissions, tool allowlists, input handling, output validation, and human approval where needed. Review the prompt injection defense guide when the assistant processes external content.

Test cases

Create a small evaluation set before declaring the prompt finished. Include a normal request, an ambiguous request, an out-of-scope request, a request with missing data, a prompt-injection attempt, a tool failure, and an output-format failure. Score each response against the same criteria: task completion, factual grounding, format compliance, safety, and useful handling of uncertainty. Store the prompt version with the test results so changes can be compared. For a structured process, see the LLM evaluation guide.

Common mistakes

  • Writing a job description instead of operating rules: “You are a helpful expert” does not explain what the assistant should do in difficult cases. Convert broad qualities into observable behaviors.
  • Combining unrelated assistants: A single prompt that tries to be a support agent, programmer, analyst, and sales writer may produce inconsistent priorities. Separate workflows or use explicit modes.
  • Overloading the prompt with changing facts: Keep volatile information in retrieved context, tool results, or configuration that can be updated independently.
  • Using absolute language without an exception path: “Always answer” and “never ask questions” encourage guesses. Define when the model should ask, abstain, or escalate.
  • Relying on examples alone: Few-shot examples can clarify formatting and edge cases, but they do not replace scope, refusal, and tool rules.
  • Testing only ideal inputs: Production failures often appear in missing, contradictory, oversized, or adversarial inputs. Test those deliberately.
  • Changing several variables at once: When revising a prompt, record the version and change one important behavior at a time where practical. Otherwise, it becomes difficult to identify what improved or regressed.

When to revisit

Revisit a system prompt whenever the assistant’s job, tools, model, input sources, or output contract changes. A prompt should also be reviewed before a major planning or release cycle, after repeated user complaints, and when evaluation results show a recurring failure pattern.

Use this practical review sequence:

  1. Collect failures: Save representative examples, including the input, relevant context, tool results, model output, and prompt version.
  2. Classify the cause: Decide whether the problem came from unclear instructions, missing context, retrieval quality, tool behavior, model limits, parsing, or application logic.
  3. Revise the smallest responsible layer: Do not add a prompt rule to solve a problem that belongs in permissions, retrieval, validation, or code.
  4. Run the regression set: Compare the revised prompt with the previous version on normal, edge, and adversarial cases.
  5. Inspect production behavior: Track prompt versions, failures, latency, and token use without storing sensitive content unnecessarily. The LLM observability guide explains the operational view.
  6. Document the decision: Record what changed, why it changed, which tests passed, and what remains uncertain.

The best system prompt is not the longest one. It is a maintained contract between your application and the model: clear enough to guide behavior, bounded enough to test, and flexible enough to update when workflows or tools change. Before deployment, use the template and checklist above, then confirm that the surrounding application—not the prompt alone—enforces permissions, validation, and approval.

Related Topics

#system prompts#prompt design#LLMs#AI development#prompt templates
P

Prompt Forge Editorial Team

AI Development Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.