{"record":{"id":"7ecc14e335be41ac","repo":"hiyouga/LlamaFactory","slug":"invalid-request","errorCode":null,"errorMessage":"Invalid request","messagePattern":"Invalid request","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"src/llamafactory/api/chat.py","lineNumber":291,"sourceCode":"        stop=request.stop,\n    ):\n        if len(new_token) != 0:\n            yield _create_stream_chat_completion_chunk(\n                completion_id=completion_id, model=request.model, delta=ChatCompletionMessage(content=new_token)\n            )\n\n    yield _create_stream_chat_completion_chunk(\n        completion_id=completion_id, model=request.model, delta=ChatCompletionMessage(), finish_reason=Finish.STOP\n    )\n    yield \"[DONE]\"\n\n\nasync def create_score_evaluation_response(\n    request: \"ScoreEvaluationRequest\", chat_model: \"ChatModel\"\n) -> \"ScoreEvaluationResponse\":\n    score_id = f\"scoreval-{uuid.uuid4().hex}\"\n    if len(request.messages) == 0:\n        raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=\"Invalid request\")\n\n    scores = await chat_model.aget_scores(request.messages, max_length=request.max_length)\n    return ScoreEvaluationResponse(id=score_id, model=request.model, scores=scores)\n","sourceCodeStart":273,"sourceCodeEnd":295,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/api/chat.py#L273-L295","documentation":"Raised as HTTP 400 by create_score_evaluation_response (the /v1/score or score-evaluation endpoint) when request.messages is an empty list. Scoring requires at least one prompt/response pair to evaluate; an empty body is rejected outright.","triggerScenarios":"POST to the score evaluation endpoint with messages: []; a batch pipeline whose upstream filtering removed all items but still sent the request; default-constructed request object.","commonSituations":"Automated eval harnesses that skip the empty-batch check; data-loading bugs producing zero rows; testing the endpoint with a placeholder payload.","solutions":["Ensure messages is non-empty before calling the endpoint; skip the call if the batch is empty.","Log batch size upstream so empty batches are visible at the source.","If you expect scores, verify you are hitting the right endpoint with the right schema rather than an intentionally empty probe."],"exampleFix":"# before\nscores = await client.score_evaluation(messages=batch)  # batch may be []\n# after\nif not batch:\n    return []\nscores = await client.score_evaluation(messages=batch)","handlingStrategy":"validation","validationCode":"if len(batch) == 0:\n    return []  # skip the call entirely\nscores = client.score_evaluation(messages=batch)","typeGuard":"const hasMessages = (req) => Array.isArray(req.messages) && req.messages.length > 0;","tryCatchPattern":"catch (e) { if (e.status === 400 && e.detail === 'Invalid request' && !req.messages?.length) { return []; /* empty batch is fine client-side */ } throw e; }","preventionTips":["Guard every batch endpoint call with an emptiness check.","Log batch sizes in pipelines so zero-length batches are visible.","Treat empty batches as no-ops, not errors, upstream."],"tags":["api","validation","scoring","http-400"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}