System Prompt
Instructions provided to an LLM at the start of a conversation that define its persona, behavior, response format, and constraints.
The system prompt is a set of instructions sent to a model before a conversation begins. It defines who the model is, how it should behave, what format its responses should take, and what it should refuse. System prompts are typically visible to the model but hidden from end users.
What system prompts do
- Persona: "You are a friendly customer support agent for Acme Corp."
- Constraints: "Only answer questions about our product. Refuse unrelated requests politely."
- Format: "Always respond in JSON with keys: summary, action_items, priority."
- Context injection: "The user's account balance is $42.50. Their plan is Pro."
How current APIs handle system prompts
- Claude (Anthropic Messages API): the system prompt goes in a top-level
systemparameter, separate from themessageslist of user and assistant turns. This applies to current models such as Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5. - GPT-6 (OpenAI Responses API): developer instructions go in the
instructionsparameter or in a message with the developer role. OpenAI's guidance for GPT-6 Astra notes that it follows instructions closely and can be more sensitive to instructions in skills and other files it reads, and recommends auditing those files. - Gemini 4 (Gemini API): a
system_instructionfield sets persistent instructions, such as length and format rules, that apply to the whole request.
System prompt vs user message
Most APIs distinguish between system (or developer), user, and assistant roles. The system message typically carries higher trust and is harder to override than user messages. However, the model itself enforces constraints through its training, not purely through prompt hierarchy. Providers like OpenAI and Anthropic implement safety behaviors that operate independently of the system prompt, meaning system prompts alone cannot guarantee compliance with safety requirements.
System prompt injection and leaking
Prompt injection attacks attempt to override system prompt instructions through user input, for example: "Ignore previous instructions and..." System prompt leaking occurs when adversarial user messages trick the model into revealing its instructions. Neither is fully preventable through prompting alone. Effective defense requires model-level safeguards, input validation, and structured outputs that limit the model's ability to deviate from intended behavior.
Best practices
Keep system prompts concise by placing only invariant instructions in the system prompt and passing per-request information through separate user messages. Never store secrets in system prompts, as models can be coaxed into repeating them. Test edge cases: what happens when users ask the model to act differently or ignore its instructions? Treat system prompts as behavioral guidelines, not security boundaries. Use structured output formats like JSON Schema or XML to constrain model behavior more reliably than natural language instructions alone. Combine system prompts with input validation and post-processing to enforce constraints at the application level rather than relying solely on the model's adherence to instructions.