本页还没有译文
本页 15 段还没译成한국어,下面显示的是英文原文。AI_InvalidPromptError
还没翻译译自英文(ai-sdk.dev)本页 15 段都还没译
This error occurs when the prompt provided is invalid.
Potential Causes
System Messages in prompt or messages
AI SDK functions reject system messages in the prompt or messages fields to reduce the risk of prompt injection.
Pass system instructions with the instructions option instead:
import { generateText } from 'ai';
const result = await generateText({
// ...
instructions: 'You are a helpful assistant.',
messages,
});If the system messages come from a trusted source, you can allow them with allowSystemInMessages: true.
Empty Messages
The messages array (or a prompt given as an array) must contain at least one message.
Provider-Specific Prompt Requirements
Some providers throw this error when a prompt can't be expressed for their API, for example when an assistant prefix message isn't the final message, or when a part combines options the provider doesn't support. The error message describes the provider requirement that wasn't met.
Note
AI SDK functions do not validate the shape of ModelMessage objects at
runtime. If your messages come from an untrusted source, validate them before
passing them to an AI SDK function. See
ModelMessage.
Properties
prompt: The invalid prompt valuemessage: The error message (required in constructor)cause: The cause of the error (optional)
Checking for this Error
You can check if an error is an instance of AI_InvalidPromptError using:
import { InvalidPromptError } from 'ai';
if (InvalidPromptError.isInstance(error)) {
// Handle the error
}