Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Tools · Const

System Prompt

A system prompt provides initial instructions that guide and constrain a model’s behavior. In the current AI SDK, pass it through instructions, alongside prompt or messages.

How it works

A system prompt gives the model initial instructions that shape and constrain its behavior. In the current API, provide those instructions through the top-level instructions option alongside either prompt or messages; system messages embedded in those fields are rejected by default.

Syntax

generateText({ model, instructions, prompt | messages, allowSystemInMessages? })

Parameters

NameTypeDescription
instructionsstring | ...Model instructions that establish system-level behavior.
promptstringA single user-facing input prompt, used alongside system instructions.
messagesModelMessage[]A conversation message list, usable alongside system instructions.
allowSystemInMessagesbooleanOpt-in switch for accepting system messages embedded in message data.

Returns

The page documents system prompts and their configuration, but does not define a standalone return value for them.

Key points

  • A system prompt establishes the model’s initial behavioral instructions.
  • Its purpose is to steer and limit the model’s behavior and output.
  • The current top-level API field for system instructions is instructions.
  • Existing histories with embedded system messages require explicit opt-in.

Common mistakes

  • Do not place a system message inside prompt or messages unless you explicitly opt into that behavior with allowSystemInMessages: true.

Example: Using instructions for a system prompt

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

const result = await generateText({
  model: openai('gpt-4o-mini'),
  instructions: 'You are a concise software engineering tutor.',
  prompt: 'Explain dependency injection in one paragraph.',
});

console.log(result.text);

The request supplies trusted system-level behavior through the top-level instructions option.

When to use it

Set model behavior

Define a stable assistant role, tone, or policy for every request.

Combine instructions with a prompt

Add system-level guidance while sending a one-shot user request.

Guide message-based interactions

Run a multi-turn conversation with trusted message history.

Interview questions

QWhat is a system prompt, and how is it configured?

A system prompt is the initial instruction set used to guide and constrain model behavior. In the current API, it is supplied with instructions, which works with both prompt and messages.

Follow-up: What should be used when an existing trusted history contains system messages? Set allowSystemInMessages: true; otherwise those messages are rejected by default.

QWhere should system instructions be placed?

Use the top-level instructions property for system-level behavior. This keeps the system instructions separate from the user-facing prompt or conversation messages.

Follow-up: Why not put the instruction in messages? Embedded system messages are rejected by default and can create injection risks when histories are not trusted.

QWhat happens when a request contains a system message in its message data?

System messages inside prompt or messages are rejected by default. To accept an existing history containing them, enable allowSystemInMessages: true, but only when the messages are trusted.

Follow-up: What is the security concern? A user who can edit the history may inject a system message that overrides or establishes the system prompt.

  • generateText
  • streamText
  • prompt
  • messages
  • ModelMessage
  • allowSystemInMessages

Source: Prompts | AI SDK. Checked 2026-10-15.