The Anthropic API performs basic prompt sanitization and validation to help ensure that your prompts are well-formatted for Claude.
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
Then, the API will validate your prompt under the following conditions:
- The first conversational turn in the prompt must be a
- The last conversational turn in the prompt be an
- The prompt must be less than
100,000 - 1tokens in length.
The following prompts will results in API errors:
# Missing "\n\nHuman:" and "\n\nAssistant:" turns prompt = "Hello, world" # Missing "\n\nHuman:" turn prompt = "Hello, world\n\nAssistant:" # Missing "\n\nAssistant:" turn prompt = "\n\nHuman: Hello, Claude" # "\n\nHuman:" turn is not first prompt = "\n\nAssistant: Hello, world\n\nHuman: Hello, Claude\n\nAssistant:" # "\n\nAssistant:" turn is not last prompt = "\n\nHuman: Hello, Claude\n\nAssistant: Hello, world\n\nHuman: How many toes do dogs have?" # "\n\nAssistant:" only has one "\n" prompt = "\n\nHuman: Hello, Claude \nAssistant:"
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:
# No leading "\n\n" for "\n\nHuman:" prompt = "Human: Hello, Claude\n\nAssistant:" # Trailing space after "\n\nAssistant:" prompt = "\n\nHuman: Hello, Claude:\n\nAssistant: "