Back to course
2 / 2

Module 2 · Lesson 2

System prompts

Steer how the model behaves by giving it a role, separate from the question you ask.

In the last lesson you sent a prompt and got an answer. In this one you learn how to shape the way the model answers, its tone, its role, its rules, without changing the question itself. This is the single most useful lever you have, and it is one extra line of code.

Learn: why a system prompt steers behaviour

There are two kinds of instruction you can give a model, and keeping them separate is what makes your app predictable.

The prompt is the specific thing you are asking right now: "What is an API key?" The system prompt is the standing instruction that applies to every answer: "You are a calm senior engineer. Explain things plainly, no jargon." The question changes from request to request. The system prompt stays put and quietly shapes all of them.

Think of it as the difference between what you ask someone and who you have asked. A system prompt sets the who. Get the who right and you stop fighting the output on every single call.

Build: add a system prompt

Open app/api/chat/route.ts from the last lesson and add an instructions line. In AI SDK 7 this is the field that holds what people usually call a system prompt:

import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

export async function GET() {
  const { text } = await generateText({
    model: anthropic("claude-opus-4-8"),
    instructions:
      "You are a calm senior engineer. Explain things in plain language, " +
      "use a short example when it helps, and never hype anything.",
    prompt: "What is an API key and why do I need one?",
  });

  return Response.json({ text });
}

The only new thing is the instructions field. Restart is not needed; just save and reload http://localhost:3000/api/chat.

Now do the experiment that makes this click. Keep the prompt exactly the same, but change only the instructions line, for example to "You are an excitable startup founder who loves buzzwords." Reload and compare. Same question, completely different voice. You did not touch the prompt at all. That separation is the whole idea.

A good system prompt is specific about behaviour, not just personality. "Answer in plain language, use a short example, never hype anything" gives the model something to act on. "Be helpful" does not.

Remix: write your own assistant

Replace the system prompt (the instructions field) with a persona you would actually use. A patient code reviewer. A study buddy that quizzes you back. A documentation writer that always includes an example. Be specific about how it should behave, not just what it is called.

Then ask it a few different questions and see if the personality holds. When you find one you like, share your system prompt in the community. Seeing how other people steer the same models is one of the fastest ways to get good at this.

Key takeaways

  • The prompt is the question; the system prompt is the standing role and rules.
  • Changing only the system prompt changes the voice without touching the question.
  • Specific, behaviour-focused system prompts beat vague ones every time.