iflytek/astron-agent · error · RequestValidationError
'content' cannot be empty
Error message
'content' cannot be empty
What it means
validate_messages_params in core/agent's OpenAI-compatible schema layer raises a fastapi RequestValidationError when any message in the request's `messages` array has empty or missing `content`. It emits a per-item error at loc body.messages[i].content with msg "'content' cannot be empty", mirroring OpenAI API validation behavior.
Solutions
- Ensure every messages[i] includes a non-empty string `content` before sending.
- For assistant tool-call messages, set content to an empty-compatible value the API accepts only if the schema allows; otherwise omit such messages or add content text.
- Trim input: reject or coalesce whitespace-only strings to a default prompt client-side.
- Check the server response loc field (body.messages[i].content) to identify the offending index.
Example fix
# before
messages = [{"role": "user"}]
# after
messages = [{"role": "user", "content": "Hello"}] Defensive patterns
Strategy: validation
Validate before calling
def validate_messages(messages):
for i, m in enumerate(messages):
if not isinstance(m, dict) or not m.get("content"):
raise ValueError(f"messages[{i}].content must be non-empty") Type guard
def has_content(m: dict) -> bool:
return isinstance(m.get("content"), str) and bool(m["content"].strip()) Try / catch
import httpx
try:
r = httpx.post(url, json=payload)
except httpx.HTTPStatusError as e:
# 422 from RequestValidationError; inspect e.response.json()['detail']
for err in e.response.json().get('detail', []):
print(err['loc'], err['msg']) Prevention
- Never append placeholder messages with empty content; fill content before queueing.
- Coalesce None/empty assistant content from tool-call flows before sending.
- Validate message payloads client-side with a shared schema (pydantic/zod).
- Read the 422 detail loc array to pinpoint the offending message index.
When it happens
Trigger: POSTing to the agent's chat/completions-style endpoint with a message dict lacking `content` (e.g. {"role":"user"}) or with content ""/null — including assistant messages that only carry tool_calls and no content.
Common situations: Client code appends a placeholder user message before filling content; assistant messages built from tool-call responses where content is None; upstream gateway strips content; hand-rolled request JSON missing the field.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- messages role order must alternate between user and…
- 'role' must be user or assistant
- app_name must not been empty
- cloud_id must not been empty
- dev_id must been more than zero
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/a3d88baa86167d83.
Report an issue: GitHub.
Appendix: source
Thrown at core/agent/api/schemas/base_inputs.py:43
@model_validator(mode="before") # type: ignore[misc]
@classmethod
def validate_messages_params(cls, values: Any) -> Any:
if not isinstance(values, dict):
return values
messages = values.get("messages", [])
if isinstance(messages, list) and not messages:
values.pop("messages", None)
return values
next_role = "user"
for i, message in enumerate(messages):
if not isinstance(message, dict):
return values
if not message.get("content"):
# Content cannot be empty
raise RequestValidationError(
errors=[
{
"type": "literal_error",
"loc": ("body", "messages", i, "content"),
"msg": "'content' cannot be empty",
}
]
)
if message.get("role") == "system":
# System role not supported
raise RequestValidationError(
errors=[
{
"type": "literal_error",
"loc": ("body", "messages", i, "role"),
"msg": "'role' must be user or assistant",
}View on GitHub (pinned to 5e758547a8)