Validation
Message Validation
Validation rules applied to the messages collections in Chat Completions and Run requests.
The following rules are enforced on message stacks:
Either directly provided via /chat/completions or built server-side by attaching messages to a thread.
All violations return an HTTP 422 Unprocessable Entity.
Content Rules
These rules apply to the content field of every message type.
| Rule | Details |
|---|---|
| Non-empty | content must not be blank or whitespace-only (applies to user, system, and tool messages) |
| Maximum length | content must not exceed 30,000 characters |
| Valid Unicode | content must be valid UTF-8; broken Unicode characters are rejected |
Assistant message content
assistant messages follow a slightly different rule:
contentmust be non-empty whentool_callsis absent.contentmust be empty whentool_callsis present.
Message List Rules
| Rule | Details |
|---|---|
| Non-empty list | The messages array must contain at least one message |
| Last message | The last message must have role user or tool |
| System message uniqueness | At most one system message is allowed |
| Assistant message ordering | An assistant message must be directly preceded by a user message |
Example — valid message stack
[
{ "role": "system", "content": "You are a helpful HR expert." },
{ "role": "user", "content": "What is BEM?" },
{ "role": "assistant", "content": "BEM stands for ...", "sources": [] },
{ "role": "user", "content": "Can you elaborate?" }
]Example — invalid: assistant without preceding user message
[
{ "role": "system", "content": "You are a helpful HR expert." },
{ "role": "assistant", "content": "BEM stands for ...", "sources": [] }
]Attachment Rules
Attachments can be added to user messages via the attachments field.
| Rule | Details |
|---|---|
| Maximum attachments | At most 1 attachment per user message |
| Global uniqueness | Each attachment is identified by its file_id, user_id, and base_url. The same attachment must not appear more than once across all messages in a single request |
Tool Message Rules
Tool messages (role: "tool") return tool call results to the assistant.
| Rule | Details |
|---|---|
| Must follow an assistant message | A tool message must be preceded by an assistant message that requested the corresponding tool call |
| All requested tool calls must be answered | If an assistant message requests multiple tool calls, all corresponding tool messages must immediately follow it |
Unique tool_call_id | Each tool_call_id must be unique across the entire messages array |
Example — valid tool message sequence
[
{ "role": "user", "content": "Search for BEM regulations." },
{ "role": "assistant", "content": "", "sources": [], "tool_calls": [
{ "id": "call_1", "type": "function", "function": { "name": "search", "arguments": "{}" } },
{ "id": "call_2", "type": "function", "function": { "name": "fetch", "arguments": "{}" } }
]},
{ "role": "tool", "content": "Search result...", "tool_call_id": "call_1" },
{ "role": "tool", "content": "Fetch result...", "tool_call_id": "call_2" }
]Example — invalid: missing tool message for call_2
[
{ "role": "user", "content": "Search for BEM regulations." },
{ "role": "assistant", "content": "", "sources": [], "tool_calls": [
{ "id": "call_1", "type": "function", "function": { "name": "search", "arguments": "{}" } },
{ "id": "call_2", "type": "function", "function": { "name": "fetch", "arguments": "{}" } }
]},
{ "role": "tool", "content": "Search result...", "tool_call_id": "call_1" }
]Tool Choice Rules
When using the tools and tool_choice fields on the request:
| Rule | Details |
|---|---|
tool_choice requires tools | tool_choice cannot be set if tools is absent or empty |
| Named tool choice must be valid | If tool_choice specifies a function by name, that function must be present in the tools list |
Defaults:
- If
toolsis provided buttool_choiceis omitted, it defaults to"auto". - If neither is provided,
tool_choicedefaults to"none".