🚀 Simplify your work by integrating Haufe Copilot via API
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.

RuleDetails
Non-emptycontent must not be blank or whitespace-only (applies to user, system, and tool messages)
Maximum lengthcontent must not exceed 30,000 characters
Valid Unicodecontent must be valid UTF-8; broken Unicode characters are rejected

Assistant message content

assistant messages follow a slightly different rule:

  • content must be non-empty when tool_calls is absent.
  • content must be empty when tool_calls is present.

Message List Rules

RuleDetails
Non-empty listThe messages array must contain at least one message
Last messageThe last message must have role user or tool
System message uniquenessAt most one system message is allowed
Assistant message orderingAn 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.

RuleDetails
Maximum attachmentsAt most 1 attachment per user message
Global uniquenessEach 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.

RuleDetails
Must follow an assistant messageA tool message must be preceded by an assistant message that requested the corresponding tool call
All requested tool calls must be answeredIf an assistant message requests multiple tool calls, all corresponding tool messages must immediately follow it
Unique tool_call_idEach 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:

RuleDetails
tool_choice requires toolstool_choice cannot be set if tools is absent or empty
Named tool choice must be validIf tool_choice specifies a function by name, that function must be present in the tools list

Defaults:

  • If tools is provided but tool_choice is omitted, it defaults to "auto".
  • If neither is provided, tool_choice defaults to "none".

On this page