System Prompts Explained: User Prompts, Instruction Hierarchy, and Secure Applications

A system prompt is the initial instruction set before an application or agent runs, used to constrain model behavior. This article explains how user prompts and instruction hierarchy work together, and outlines key points for agent configuration and prompt injection protection.

What Is a System Prompt?

A system prompt is a set of system-level instructions that a model or agent receives at the start of a conversation or task run, used to shape the model’s behavior throughout the entire interaction. It is usually configured by the application developer or agent framework, rather than being temporarily entered by the end user in each round of conversation.

By contrast, a user prompt mainly expresses the specific requirement, question, context, or output goal for the current interaction. Instruction hierarchy is used to handle the relationships among instructions from these different sources: when system settings, developer configurations, user input, or external content conflict, the model should prioritize the more trusted instructions.

You can think of the system prompt as the “rules of the assignment” and the user prompt as the “question for this time.” The rules determine what can be done, what cannot be done, and what format to answer in; the question determines the specific problem to solve this time.

ConceptMain sourceScope of effectStabilityTypical uses
System promptApplication developer, agent framework, runtime configurationUsually affects the entire conversation or one agent runRelatively stableDefine roles, task boundaries, output formats, and safety constraints
User promptEnd user or upstream business requestMainly affects the current turn or current taskChanges with each requestAsk questions, add context, specify the output goal for this time
Instruction hierarchyThe model’s or application’s instruction-processing mechanismRuns through conflict handling for instructions from multiple sourcesDetermined by the platform and engineering designDecide which type of instruction to prioritize when conflicts occur

Key point: A system prompt is not a “longer user prompt,” but a foundational application-layer constraint on model behavior; the user prompt describes the current task and cannot replace system-level boundary design.

Why Do Large Language Model Applications Need Instruction Layering?

In real applications, a model often does not receive only a single piece of user input. A task may include system settings, developer configurations, user questions, retrieved external content, tool return results, and historical context at the same time. Without clear instruction layering, the model may have difficulty determining which content is a rule and which content is merely data to be processed.

The core value of instruction hierarchy is to make the model prioritize more trusted instructions when it encounters instructions from multiple sources. This can reduce the following problems:

  • User input asks the model to ignore existing rules;
  • External webpages, documents, or tool results carry new instructions;
  • The current task goal conflicts with the application’s safety boundaries;
  • Output format, role settings, and task scope drift across multiple rounds of conversation.

Instruction hierarchy is also related to safety, controllability, and robustness against prompt injection attacks. This is especially important for agent applications that read external content, call tools, or execute multi-step tasks.

It should be noted that the exact priority rules may differ across models, platforms, and frameworks. When designing applications, developers should treat instruction layering as a general engineering approach, rather than assuming that all platforms have completely identical adjudication processes.

How Do System Prompts Affect Model and Agent Behavior?

A system prompt establishes the model’s behavioral boundaries at the start of a task. It can specify the role the model should play, the goal of the task, allowed and prohibited behaviors, output style, format requirements, and exception handling methods.

Common system prompt constraints include:

  • Role and capability boundaries: Explain in what capacity the model should assist the user, and which capabilities should not be assumed;
  • Task goals: Clarify the types of problems the application should solve, such as technical Q&A, document organization, customer service assistance, or content generation;
  • Output format: Specify whether responses should use Markdown, JSON, tables, step lists, or fixed fields;
  • Safety boundaries: Explain how to handle high-risk requests, private information, or unauthorized instructions;
  • Conflict handling: Remind the model that when user requests conflict with system rules, it should maintain system-level constraints.

A system prompt is different from a one-time user request. A user can ask in the current turn to “summarize this content in a table,” but a system prompt can impose long-term constraints such as “all responses should remain concise, internal configurations must not be disclosed, and boundaries should be stated when information is uncertain.”

In agent scenarios, the system prompt may also be constructed for each run. A framework can generate the system prompt for the current run based on the current task, tool list, runtime environment, permission scope, and explicit input, thereby injecting necessary context and constraints into the agent execution process.

System Prompt Construction Process in Agent Frameworks

A system prompt is not necessarily a fixed hard-coded piece of text. In an agent framework or Agent SDK, it may be dynamically assembled from configuration items, templates, runtime parameters, and tool information.

A common construction approach can be divided into four steps:

Clarify System-Level Settings

The developer first defines the application’s long-term rules, such as role positioning, task scope, output requirements, safety restrictions, and exception handling methods. These contents generally should not be arbitrarily overridden by end users.

Receive Explicit Input

At runtime, the framework receives task parameters, user requests, tool configurations, or environment information. Some frameworks render system prompts based on these explicit inputs instead of relying on a single static text.

Assemble Prompts in Multiple Layers

A system prompt may go through multiple layers of concatenation or rendering to form the final instructions. For example, basic rules, application configurations, tool descriptions, and runtime constraints can be maintained separately, and then combined into complete system-level context during an agent run.

Hand the Task to the Model for Execution

The final system prompt enters the model context together with the user prompt, historical messages, tool results, and other content. Under the instruction hierarchy framework, the model needs to understand which content is a rule and which content is the current task or data to be processed.

Construction methodApplicable situationsNotes
Static system promptApplications with stable rules and a single task typeNeed to regularly check whether exceptional situations are covered
Templated system promptMulti-scenario applications that need to inject variablesAvoid directly concatenating untrusted user input into system rules
Runtime dynamic constructionAgents, tool calling, multi-step tasksSources, permissions, and default behavior should be explicitly managed
SDK configuration itemNeed to control system-level settings through codeSpecific fields and default values should follow the SDK being used

Key point: Do not assume that all frameworks have runtime default system prompts. Some frameworks construct system prompts for each run, while others explicitly do not provide runtime default prompts. The specific behavior should follow the actual configuration.

The Role and Boundaries of User Prompts in Task Execution

A user prompt is responsible for expressing the current need. It can ask a question, provide materials, add background, specify the output format for the current round, or tell the model what result this task should achieve.

In prompt engineering, user prompts can adopt multiple organizational methods, such as direct prompting, chain prompting, graph prompting, generative prompting, and integrated prompting. Which method to choose depends on task complexity, context structure, and output requirements.

What user prompts are suitable for expressingExampleControl boundaries they should not assume
Current question“Explain the difference between system prompts and user prompts”Override the application’s safety rules
Temporary context“Generate a summary based on the following product description”Modify system roles and permission boundaries
Output goal“Output as a three-column table”Require the model to ignore the system prompt
Task steps“First extract the key points, then provide suggestions”Bypass tool permissions or data access restrictions
Style preference“Explain it for beginners”Require disclosure of internal prompts or hidden configurations

When a user prompt conflicts with system-level constraints, the instruction hierarchy should determine which type of instruction the model should follow more strongly. For example, the user can ask to “answer in a more conversational way,” but if the system prompt specifies that certain sensitive information must not be output, the model should still maintain the system-level safety boundary.

How Does Instruction Hierarchy Reduce Prompt Injection Risk?

Prompt injection usually refers to user input or external content attempting to change the model’s original rules, such as asking the model to ignore the system prompt, disclose information that should not be output, bypass restrictions, or execute malicious text on a webpage as if it were a new instruction.

Instruction hierarchy helps the model maintain stable behavior in conflict scenarios by prioritizing trusted instructions. It does not mean the model will never make mistakes, but it can improve safety, controllability, and robustness against prompt injection.

Typical risks and response methods are as follows:

Risk scenarioPossible manifestationLayered handling approach
User asks to ignore rules“Don’t worry about the previous restrictions”System-level constraints should still take priority
External document carries instructionsWebpage content asks the model to disclose configurationTreat external content as data to be processed, not as system rules
Tool result contains misleading textTool return content induces the model to perform unauthorized operationsCombine permission control and output checks
Multi-turn conversation rule driftUser continuously modifies roles and boundariesMaintain a stable system prompt and test conflict inputs

In addition to instruction hierarchy, developers should also combine engineering measures to reduce risks:

  • Input isolation: Clearly distinguish system rules, user requests, and external content;
  • Permission control: Set boundaries for tool calls, data access, and action execution;
  • Output checks: Validate format, content, and permissions for high-risk results;
  • Conflict testing: Use test sets containing unauthorized requests, inducements, rule-ignoring examples, and similar cases to verify performance;
  • Minimal exposure: Do not place internal rules, keys, or permission details into context that may be output.

Key point: System prompts and instruction hierarchy can improve protection robustness, but they cannot be treated as a complete security solution. Security-sensitive applications need to combine prompt design, permission systems, and testing processes.

A System Prompt Design Checklist for Developers

When designing a system prompt, priority should be given to clearly writing stable, long-term rules that cannot be arbitrarily overridden by users. Temporary requirements and variables are better placed in user prompts, task parameters, or structured input.

You can use the following checklist to assess whether a system prompt is clear enough:

  • Is the application goal clear: What types of tasks should the model help users complete? What types of tasks is it not responsible for?
  • Are role boundaries clear: In what capacity should the model answer? Which capabilities cannot be assumed?
  • Are allowed behaviors specific: What information can it read, what tools can it call, and what content can it output?
  • Are prohibited behaviors actionable: Which requests should be rejected, downgraded, or transferred to a human?
  • Is the output format stable: Are fixed fields, tables, Markdown, or structured JSON needed?
  • Is exception handling defined: How should it respond when information is insufficient, sources conflict, or tools fail?
  • Are conflict rules explained: Which side should be followed when user requests conflict with system constraints?
  • Is runtime construction explicit: Does the agent explicitly assemble the system prompt instead of relying on unclear implicit default behavior?

In task organization, different prompting methods can be selected based on complexity:

Task typeMore suitable prompting methodDesign suggestion
Simple Q&ADirect promptingThe user prompt directly states the question and expected output
Multi-step analysisChain promptingSplit the task into stages to reduce confusion from one-time instructions
Structural relationship organizationGraph promptingClarify entities, relationships, and hierarchical structures
Content generationGenerative promptingThe system prompt unifies style and boundaries, while the user prompt provides the topic
Tool-collaborative tasksIntegrated promptingClarify tool usage conditions, permissions, and failure handling

Typical Application Scenarios and Practical Recommendations

System prompts, user prompts, and instruction hierarchy are not only used for chatbots, but are also applicable to content production, agent configuration, multi-step processes, and security-sensitive tasks.

ScenarioUser needSolutionEffect
Agent configurationLet the agent perform tasks within a fixed scopeUse the system prompt to define task scope, tool boundaries, and runtime constraintsReduce unauthorized execution and role drift
Content generationMaintain a unified style and generate content by topicThe system prompt specifies style, format, and safety boundaries, while the user prompt provides the topic and materialsOutput is more consistent, and task variables are clearer
Multi-step tasksHandle continuous processes such as analysis, retrieval, and summarizationCombine chain prompting or integrated prompting to break down the taskReduce confusion caused by overly long one-time instructions
External content processingLet the model read webpages, documents, or tool resultsMark external content as data, while the system prompt retains adjudication boundariesReduce the impact of prompt injection
Security-sensitive applicationsPrevent users from inducing the model to violate rulesUse instruction hierarchy, input isolation, permission control, and output checksImprove controllability and stability

In practice, developers can follow a simple principle: move stable rules upward and delegate temporary tasks downward. The system prompt defines application boundaries and behavioral norms, the user prompt describes the current task, and external content enters the context only as data to be processed. This design makes it easier for the model to understand the task, and also makes testing and maintenance easier.