Skip to content

Commit 1d13b56

Browse files
Your Nameclaude
andcommitted
fix: validate message roles — return 400 instead of 500 for invalid roles
Round 5 testing (Python agent developer) found that sending an invalid role like "bot" caused a 500 Internal Server Error from the tokenizer. Now validates roles against {system, user, assistant, tool, developer} and returns a clear 400 error with the invalid role name. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4c972c9 commit 1d13b56

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

vllm_mlx/server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,15 @@ async def create_chat_completion(request: ChatCompletionRequest, raw_request: Re
17011701
detail="messages must not be empty",
17021702
)
17031703

1704+
# Validate message roles
1705+
_valid_roles = {"system", "user", "assistant", "tool", "developer"}
1706+
for msg in request.messages:
1707+
if msg.role not in _valid_roles:
1708+
raise HTTPException(
1709+
status_code=400,
1710+
detail=f"Invalid role '{msg.role}'. Must be one of: {', '.join(sorted(_valid_roles))}",
1711+
)
1712+
17041713
# Validate top_logprobs range (OpenAI spec: 0-20)
17051714
if request.top_logprobs is not None and (
17061715
request.top_logprobs < 0 or request.top_logprobs > 20

0 commit comments

Comments
 (0)