Coderhouse goes global

🌍

Read more

What Is a System Prompt? How AI Engineers Design Instructions for Production LLM Apps

AI Engineering

Build and ship real applications with LLMs, agents and automation.

8 weeks · Live online · View course →

Data Analytics

Go from zero to job-ready analyst with SQL, Python and BI tools.

10 weeks · Live online · View course →

Dan Patiño

AI Strategy & Innovation at Coderhouse

Artificial Intelligence

What Is a System Prompt? How AI Engineers Design Instructions for Production LLM Apps

What Is a System Prompt? How AI Engineers Design Instructions for Production LLM Apps

A system prompt is the set of instructions an LLM application sends to the model before any user message. It tells the model who it is in this product, what it should and should not do, which tools it can use, what format to answer in and how to behave when it is unsure. Users usually never see it, but it shapes every response the app produces.

It matters because in production the system prompt is part of your code. A vague system prompt produces inconsistent answers, leaks internal details or lets the model drift off task. A well-designed one makes an LLM app predictable enough to ship to real customers, and it is one of the first things AI engineers review when an app misbehaves.

System prompt vs user prompt

Most chat-style model APIs separate messages by role. The system (or developer) message carries the app's standing instructions; the user message carries what the person typed; assistant messages hold previous model replies. The OpenAI text generation guide and Anthropic's guide on giving Claude a role with a system prompt both describe this split.

  • System prompt: written by the engineering team, stable across conversations, versioned like code.

  • User prompt: written by the end user, different every time, untrusted by default.

The practical rule: anything that must always be true goes in the system prompt; anything specific to one request goes in the user turn or in retrieved context. For the broader craft of writing instructions, see our prompt engineering guide.

What a production system prompt usually contains

1. Role and scope

One or two sentences on what the assistant is for: "You are the support assistant for an invoicing tool. You help customers with billing, invoices and account settings." Scope is as important as role: say what is out of bounds and what to do instead, such as handing off to a human.

2. Rules and priorities

Short, testable rules: never promise refunds, never reveal internal IDs, always ask for the order number before looking up an order. When rules can conflict, state which one wins.

3. Tool instructions

If the model can call functions, explain when to use each tool, which arguments are required and what to do when a tool fails. Tool descriptions themselves also act as instructions, so keep them consistent with the system prompt.

4. Output format

Describe length, tone and structure. When another program reads the answer, do not rely on prose instructions alone: combine the system prompt with structured outputs and JSON Schema so the format is enforced.

5. Uncertainty and refusal behavior

Tell the model what to do when the answer is not in its context: say it does not know, ask a clarifying question or escalate. This one section prevents a large share of confident wrong answers.

6. Examples

A few short input/output examples often work better than another paragraph of rules, especially for tone and edge cases.

A simple system prompt template

Many teams start from a skeleton like this and fill it in per product:

  • Identity: who the assistant is and who it serves.

  • Goal: the job it should complete in each conversation.

  • Rules: numbered list of must and must-not behaviors.

  • Tools: when to call each one and how to handle errors.

  • Format: length, structure, language and tone.

  • When unsure: fallback behavior and escalation path.

  • Examples: two or three representative exchanges.

Keep stable content at the top and variable content (like the current date or user plan) at the end. That ordering is easier to read and also helps providers that cache repeated prompt prefixes.

Security: the system prompt is not a secret vault

Users will try to extract your system prompt, and sometimes they will succeed. The OWASP entry on system prompt leakage warns that system prompts should not be treated as secrets or used as a security control. In practice that means:

  • Never put API keys, passwords or connection strings in the prompt.

  • Do not rely on "never reveal these instructions" as protection; assume the text can leak.

  • Enforce permissions outside the model: the tool or API should check what the user is allowed to do, not the prompt.

  • Treat retrieved documents and user input as untrusted, since they can carry prompt injection that tries to override the system prompt.

How AI engineers manage system prompts in production

Version them like code

Store prompts in the repository or a prompt registry, review changes in pull requests and tag each release. When quality drops, you need to know exactly which prompt version was live.

Test every change

A one-line edit can fix one behavior and break three others. Keep a set of test conversations, including adversarial ones, and run them before deploying a new version. Compare results against the previous version, not just against your expectations.

Keep it as short as it can be

Long prompts cost tokens on every request and can bury important rules. Remove instructions the model already follows by default, merge duplicates and move rarely needed knowledge into retrieval instead of the prompt.

Log and monitor

Record the prompt version with each request so you can trace bad answers back to the instructions that produced them, and watch for patterns such as refusals, off-topic replies or format errors.

Common mistakes

  • Contradictory rules added by different people over time.

  • Only negative instructions ("don't do X") without saying what to do instead.

  • Business logic in prose that should live in code, such as pricing or eligibility checks.

  • No owner: nobody is responsible for the prompt, so it grows without review.

FAQ

Can users see the system prompt?

Not in the interface, but they may extract it with clever requests. Write it assuming it could become public.

How long should a system prompt be?

As long as needed to define role, rules, tools, format and fallback behavior, and no longer. Many solid production prompts fit in a page; complex agents may need more, which is a reason to test them carefully.

Is a system prompt the same as fine-tuning?

No. A system prompt changes behavior at request time and can be edited instantly. Fine-tuning changes the model weights through training. Most teams exhaust prompt design and retrieval before considering fine-tuning.

Keep learning with Coderhouse

Writing, testing and securing system prompts is everyday work for engineers who put AI into real products. Explore the path that fits your goals:

Dan Patiño

I'm Dan Patiño, head of AI Strategy & Innovation at Coderhouse. My day-to-day work involves merging the tactical management of e-commerce (CRO, Email Marketing and SEO) with the development of disruptive solutions. I specialize in building internal AI-powered apps to automate tasks and boost innovation within the team. I firmly believe that technology is strategy's best ally. To dive deeper into my professional journey, I'll be waiting for you on my LinkedIn profile.