Prompt validation
With Text Completions
Legacy API
The Text Completions API is a legacy API. Future models and features will require use of the Messages API, and we recommend migrating as soon as possible.
The Anthropic API performs basic prompt sanitization and validation to help ensure that your prompts are well-formatted for Claude.
When creating Text Completions, if your prompt is not in the specified format, the API will first attempt to lightly sanitize it (for example, by removing trailing spaces). This exact behavior is subject to change, and we strongly recommend that you format your prompts with the recommended alternating \n\nHuman:
and \n\nAssistant:
turns.
Then, the API will validate your prompt under the following conditions:
- The first conversational turn in the prompt must be a
\n\nHuman:
turn - The last conversational turn in the prompt be an
\n\nAssistant:
turn - The prompt must be less than
100,000 - 1
tokens in length.
Examples
The following prompts will results in API errors:
The following are currently accepted and automatically sanitized by the API, but you should not rely on this behavior, as it may change in the future: