{"record":{"id":"a3d88baa86167d83","repo":"iflytek/astron-agent","slug":"content-cannot-be-empty","errorCode":null,"errorMessage":"'content' cannot be empty","messagePattern":"'content' cannot be empty","errorType":"validation","errorClass":"RequestValidationError","httpStatus":422,"severity":"error","filePath":"core/agent/api/schemas/base_inputs.py","lineNumber":43,"sourceCode":"\n    @model_validator(mode=\"before\")  # type: ignore[misc]\n    @classmethod\n    def validate_messages_params(cls, values: Any) -> Any:\n        if not isinstance(values, dict):\n            return values\n        messages = values.get(\"messages\", [])\n        if isinstance(messages, list) and not messages:\n            values.pop(\"messages\", None)\n            return values\n\n        next_role = \"user\"\n        for i, message in enumerate(messages):\n            if not isinstance(message, dict):\n                return values\n\n            if not message.get(\"content\"):\n                # Content cannot be empty\n                raise RequestValidationError(\n                    errors=[\n                        {\n                            \"type\": \"literal_error\",\n                            \"loc\": (\"body\", \"messages\", i, \"content\"),\n                            \"msg\": \"'content' cannot be empty\",\n                        }\n                    ]\n                )\n\n            if message.get(\"role\") == \"system\":\n                # System role not supported\n                raise RequestValidationError(\n                    errors=[\n                        {\n                            \"type\": \"literal_error\",\n                            \"loc\": (\"body\", \"messages\", i, \"role\"),\n                            \"msg\": \"'role' must be user or assistant\",\n                        }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/agent/api/schemas/base_inputs.py#L25-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nmessages = [{\"role\": \"user\"}]\n\n# after\nmessages = [{\"role\": \"user\", \"content\": \"Hello\"}]","handlingStrategy":"validation","validationCode":"def validate_messages(messages):\n    for i, m in enumerate(messages):\n        if not isinstance(m, dict) or not m.get(\"content\"):\n            raise ValueError(f\"messages[{i}].content must be non-empty\")","typeGuard":"def has_content(m: dict) -> bool:\n    return isinstance(m.get(\"content\"), str) and bool(m[\"content\"].strip())","tryCatchPattern":"import httpx\ntry:\n    r = httpx.post(url, json=payload)\nexcept httpx.HTTPStatusError as e:\n    # 422 from RequestValidationError; inspect e.response.json()['detail']\n    for err in e.response.json().get('detail', []):\n        print(err['loc'], err['msg'])","preventionTips":["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."],"tags":["api","validation","openai-compatible","fastapi"],"backgroundTag":"empty-required-field","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}