Set model behavior
Define a stable assistant role, tone, or policy for every request.
AI Tools · Const
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.
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.
generateText({ model, instructions, prompt | messages, allowSystemInMessages? })| Name | Type | Description |
|---|---|---|
instructions | string | ... | Model instructions that establish system-level behavior. |
prompt | string | A single user-facing input prompt, used alongside system instructions. |
messages | ModelMessage[] | A conversation message list, usable alongside system instructions. |
allowSystemInMessages | boolean | Opt-in switch for accepting system messages embedded in message data. |
The page documents system prompts and their configuration, but does not define a standalone return value for them.
instructions.prompt or messages unless you explicitly opt into that behavior with allowSystemInMessages: true.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.
Define a stable assistant role, tone, or policy for every request.
Add system-level guidance while sending a one-shot user request.
Run a multi-turn conversation with trusted message history.
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.
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.
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.
generateTextstreamTextpromptmessagesModelMessageallowSystemInMessages