mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(vertex-ai): set response=null on batch error entries per OpenAI spec
The Vertex batch output transformer was emitting both a populated 'response' and 'error' for failed batch entries. The OpenAI Batch output spec defines them as mutually exclusive: on error 'response' MUST be null. This broke any consumer using 'result["response"] is None' to detect failures.
This commit is contained in:
parent
439217511a
commit
946dfb63c7
2 changed files with 8 additions and 30 deletions
|
|
@ -731,25 +731,13 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig):
|
|||
has_error = bool(status)
|
||||
|
||||
if has_error:
|
||||
# Return error response in OpenAI format
|
||||
return {
|
||||
"id": f"batch_req_{uuid.uuid4()}",
|
||||
"custom_id": custom_id,
|
||||
"response": {
|
||||
"status_code": 400,
|
||||
"request_id": "",
|
||||
"body": {
|
||||
"error": {
|
||||
"message": status,
|
||||
"type": "vertex_ai_error",
|
||||
"code": "vertex_ai_error",
|
||||
}
|
||||
},
|
||||
},
|
||||
"response": None,
|
||||
"error": {
|
||||
"message": status,
|
||||
"type": "vertex_ai_error",
|
||||
"code": "vertex_ai_error",
|
||||
"message": status,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -789,25 +777,13 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig):
|
|||
}
|
||||
|
||||
except Exception as e:
|
||||
# If transformation fails, return error
|
||||
return {
|
||||
"id": f"batch_req_{uuid.uuid4()}",
|
||||
"custom_id": custom_id,
|
||||
"response": {
|
||||
"status_code": 500,
|
||||
"request_id": "",
|
||||
"body": {
|
||||
"error": {
|
||||
"message": f"Failed to transform response: {str(e)}",
|
||||
"type": "transformation_error",
|
||||
"code": "transformation_error",
|
||||
}
|
||||
},
|
||||
},
|
||||
"response": None,
|
||||
"error": {
|
||||
"message": f"Failed to transform response: {str(e)}",
|
||||
"type": "transformation_error",
|
||||
"code": "transformation_error",
|
||||
"message": f"Failed to transform response: {str(e)}",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -431,10 +431,12 @@ class TestVertexBatchOutputTransformation:
|
|||
)
|
||||
result = json.loads(transformed_content.decode("utf-8"))
|
||||
|
||||
# Verify error format
|
||||
assert result["response"]["status_code"] == 400
|
||||
# Per OpenAI Batch output spec, error entries set response to null
|
||||
# and populate the top-level error object.
|
||||
assert result["response"] is None
|
||||
assert result["error"] is not None
|
||||
assert "Invalid request" in result["error"]["message"]
|
||||
assert result["error"]["code"] == "vertex_ai_error"
|
||||
assert result["custom_id"] == "request-error"
|
||||
|
||||
def test_transform_vertex_batch_output_legacy_labels_only_sanitized(self, config):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue