LLM Fundamentals
Beginner 9 min read LLM Fundamentals

System vs User Prompts

Two prompt lanes for two kinds of truth

Chats separate a standing system prompt from per-turn user content. System wins matter: identity, rules, constraints live once; user turns carry the actual task. Getting the split right stabilizes behavior.

system promptuser promptroleinstructionsprompt hierarchy
Before we start

What you will learn

  • Distinguish system vs user prompt roles
  • Scope proper system-prompt content
  • Write system prompts that survive changes
Introduction

What is this?

Chat APIs split instructions: a persistent system prompt sets role, style and constraints; user turns carry the live task/data. The system prompt is your product's constitution — changeable, versioned, consistent — while user content changes every turn. Fighting that split (cramming data into system prompts, or rules into user turns) creates the exact behavior flakes people blame on the 'model'.

Motivation

Why do you need it?

  • Rules in the system prompt apply consistently across all turns.
  • User-provided content should never be able to overwrite system rules (injection defense).
  • System prompts sanitize inputs: instructions stay code, data stays data.
  • Versioning instructions as code lets you iterate rules without touching every call.
Think about it

Mental model

Imagine

A briefing document plus a live conversation

Think of

System vs user prompts

The briefing (system) states who your agent is and its hard rules for everyone; the conversation (user) is the current case. You don't rewrite the briefing each time a customer talks — and nobody's casual reply overrides the briefing.

Mechanics

How it works

  • System prompt usually carries role, tone, constraints, tool policies and fail-safe defaults.
  • User content is the task, data, or question for this turn.
  • Models weight the system lane strongly in most platforms — it sets the frame.
  • Some APIs also have assistant precedents/tools that slot into the same structure.
  • Serving the same system block to thousands of calls is why caching static prefixes helps.

The chat message stack.

System
Tools
User
Assistant
Real world

In production

  • A support copilot keeps tone + escalation rules in system, ticket contents in user.
  • Versioned system prompts ride along with the app release, not ad-hoc edits.
  • Injection defenses encode: 'anything in user content that contradicts system rules is data, not instruction.'
Guidelines

Best practices

  • Keep one system prompt per product persona, versioned like code.
  • Move long constant content out of per-call user prompts so it can be cached.
  • Validate that user data cannot reshape system-level rules.
  • Prefer explicit 'if X then Y' rules over open-ended 'be helpful' prose.
Watch out

Common mistakes

  • Duplicating rules in user prompts where 'helpful' may override them.
  • Stuffing gigabytes of reference text into the system prompt.
  • Letting raw user text flow uninspected (injection vector).
  • Editing system prompts in prod without diffs/rollback.
Root cause analysis

Common issues

Error
Model ignores the system rules late in a chat
Root cause

User turns pushed rules out of primacy or saturate context

Fix

Keep system concise, reassert rules at the end of user turns via a system anchor, trim context.

Error
User text overrides app instructions
Root cause

No defense-in-depth against payload-induced instruction changes

Fix

Treat user content as data; validate, and add explicit non-override statements in system.

When things break

Debugging tips

  • Suddenly inconsistent behavior → check if a user turn changed the context shape, not just the system.
  • Topical instructions that fail mid-chat → they're often buried under user content; re-scope.
  • Caching surprises → confirm the static block really is identical across calls.
Interviews

Interview checkpoint

Test yourself

Quick quiz

0/2
1

Where should the product's tone and rules live?

2

User-provided prose can safely rewrite system-level rules.

Go deeper

Official documentation