oobabooga/textgen · error · InvalidRequestError
messages: missing content
Error message
messages: missing content
What it means
Every message must have non-null 'content', except assistant messages that carry 'tool_calls' (OpenAI permits content:null there; the server coerces those to empty string). Any other message whose content is None (or absent) raises InvalidRequestError (400, param='messages').
Source
Thrown at modules/api/completions.py:509
tool_choice = body.get('tool_choice', None)
if tool_choice == "none":
tools = None # Disable tool detection entirely
messages = body['messages']
for m in messages:
if 'role' not in m:
raise InvalidRequestError(message="messages: missing role", param='messages')
elif m['role'] == 'function':
raise InvalidRequestError(message="role: function is not supported.", param='messages')
# Handle multimodal content validation
content = m.get('content')
if content is None:
# OpenAI allows content: null on assistant messages when tool_calls is present
if m['role'] == 'assistant' and m.get('tool_calls'):
m['content'] = ''
else:
raise InvalidRequestError(message="messages: missing content", param='messages')
# Validate multimodal content structure
if isinstance(content, list):
for item in content:
if not isinstance(item, dict) or 'type' not in item:
raise InvalidRequestError(message="messages: invalid content item format", param='messages')
if item['type'] not in ['text', 'image_url']:
raise InvalidRequestError(message="messages: unsupported content type", param='messages')
if item['type'] == 'text' and 'text' not in item:
raise InvalidRequestError(message="messages: missing text in content item", param='messages')
if item['type'] == 'image_url' and ('image_url' not in item or 'url' not in item['image_url']):
raise InvalidRequestError(message="messages: missing image_url in content item", param='messages')
# Chat Completions
object_type = 'chat.completion' if not stream else 'chat.completion.chunk'
created_time = int(time.time())
cmpl_id = "chatcmpl-%d" % (int(time.time() * 1000000000))
resp_list = 'data' if is_legacy else 'choices'View on GitHub (pinned to ed888c71f2)
Solutions
- Set content to a string (empty "" is acceptable) for every non-tool-call message.
- For assistant tool-call messages, include a non-empty 'tool_calls' array if content is null, or just set content to ''.
- Guard client-side: replace None content with '' before sending.
Example fix
# before
messages.append({"role": "user", "content": None if not q else q})
# after
messages.append({"role": "user", "content": q or ""}) Defensive patterns
Strategy: validation
Validate before calling
def ensure_content(messages):
for m in messages:
if m.get('content') is None:
if m.get('role') == 'assistant' and m.get('tool_calls'):
m['content'] = ''
else:
m['content'] = '' # or raise your own error before the API call
return messages Type guard
def message_has_content(m) -> bool:
return m.get('content') is not None or (m.get('role') == 'assistant' and bool(m.get('tool_calls'))) Try / catch
try:
resp = client.chat.completions.create(model=m, messages=msgs)
except openai.BadRequestError as e:
if 'missing content' in str(e):
msgs = ensure_content(msgs)
resp = client.chat.completions.create(model=m, messages=msgs)
else:
raise Prevention
- Default content to '' when user input may be None.
- Keep tool_call_id-bearing assistant messages and their tool replies in pairs.
- Validate with a type guard in your message-append helper.
When it happens
Trigger: POST /v1/chat/completions with {"role": "user", "content": null}, a message dict that omits 'content', or an assistant tool-call message where content is null but 'tool_calls' is also missing/empty.
Common situations: Client code doing messages.append({"role": "user", "content": user_input}) with user_input=None; multimodal pipelines that null out content; sending an assistant message with tool_calls=[] (falsy) plus content:null, which fails the exception branch.
Related errors
- messages: missing role
- functions is not supported.
- function_call is not supported.
- messages is required
- role: function is not supported.
AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15).
Data as JSON: /api/errors/6e17ff0005013f51.
Report an issue: GitHub.