fix(watsonx): wrap string embedding input in array for WatsonX API#30897
Conversation
WatsonX text/embeddings expects inputs as []string; OpenAI clients often send a single string. Co-authored-by: Cursor <[email protected]>
|
Shivam Rawat seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Greptile SummaryThis PR fixes a WatsonX embedding failure where a single-string
Confidence Score: 5/5Safe to merge — the change is a one-function normalisation with no effect on other code paths. The fix is surgical: a 10-line normalisation block added before the return statement of a single method, with no changes to surrounding logic, auth handling, or response parsing. The three new unit tests directly exercise the added branches and confirm the before/after payload shape. No existing tests were modified, no production code outside the WatsonX embedding transformation was touched. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/watsonx/embed/transformation.py | Adds input normalization in transform_embedding_request: wraps string inputs in a list and rejects token-array inputs (List[int] / List[List[int]]) that WatsonX does not support. Change is minimal and correct. |
| tests/test_litellm/llms/watsonx/embed/test_watsonx_embedding_transformation.py | New test file covering string-wrapping, list pass-through, and token-array rejection. All tests are pure unit tests with no network calls, satisfying the mock-only constraint for this folder. |
Reviews (2): Last reviewed commit: "fix(watsonx): avoid UP006 in embed trans..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: Cursor <[email protected]>
Use list[str] and branch-based input normalization instead of List and cast so the watsonx embedding change does not add strict ruff UP006 violations. Co-authored-by: Cursor <[email protected]>
|
@greptile review again with all commits as we resolved linting issues |
c7efa77
into
litellm_internal_staging
…erriAI#30897) * fix(watsonx): wrap string embedding input in array for WatsonX API WatsonX text/embeddings expects inputs as []string; OpenAI clients often send a single string. Co-authored-by: Cursor <[email protected]> * style(watsonx): format watsonx embed transformation for black Co-authored-by: Cursor <[email protected]> * fix(watsonx): avoid UP006 in embed transformation strict lint gate Use list[str] and branch-based input normalization instead of List and cast so the watsonx embedding change does not add strict ruff UP006 violations. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Shivam Rawat <[email protected]> Co-authored-by: Cursor <[email protected]>
WatsonX embedding requests fail with 400 invalid_request_entity when input is sent as a single string (valid OpenAI format)
Issue
Calling /v1/embeddings on the proxy with a WatsonX model (e.g. multilingual-e5-large backed by watsonx/intfloat/multilingual-e5-large) and a string input returns:
WatsonxException - Failed to deserialize json: 'Mismatch type []string with value string'
The upstream payload shows "inputs":"cdsc" instead of "inputs":["cdsc"]. OpenAI clients and the LiteLLM UI commonly send "input": "cdsc" for single-text embeddings, so this breaks the normal embedding path for WatsonX.
Root cause
IBMWatsonXEmbeddingConfig.transform_embedding_request passed the OpenAI input value straight through as WatsonX inputs. OpenAI accepts both a string and a list of strings; WatsonX /ml/v1/text/embeddings always expects inputs to be []string. A string input was serialized as a JSON string, which WatsonX rejected.
Fix
Normalize input before building the WatsonX request body: wrap a single string in a one-element list, pass through an existing list of strings unchanged, and raise a clear error for token-array inputs (which WatsonX does not support).
Added regression tests in tests/test_litellm/llms/watsonx/embed/test_watsonx_embedding_transformation.py covering string input, list input, and token-array rejection.
Screenshots / Proof of Fix
Before (broken payload sent to WatsonX):
{"inputs":"cdsc","parameters":{...},"model_id":"intfloat/multilingual-e5-large","project_id":"..."}
After fix, unit test + mocked integration confirm the payload is:
{"inputs":["cdsc"],"parameters":{...},"model_id":"intfloat/multilingual-e5-large","project_id":"..."}
Live proxy repro (restart proxy after pulling this branch):
Type
Bug Fix
Changes
litellm/llms/watsonx/embed/transformation.py: wrap string input into inputs: [str] before calling WatsonX
tests/test_litellm/llms/watsonx/embed/test_watsonx_embedding_transformation.py: regression tests for string, list, and token-a