BerriAI/litellm · error · Exception

Mock error

Error message

Mock error

What it means

mock_embedding (used when mock_response is set on litellm.embedding) raises Exception('Mock error') when mock_response == 'error'. This is intentional: passing the literal string 'error' instructs litellm to simulate a failed embedding call, which is how tests exercise error handling, fallbacks, and router retries without a real provider.

Source

Thrown at litellm/litellm_core_utils/mock_functions.py:14

from ..types.utils import (
    Embedding,
    EmbeddingResponse,
    ImageObject,
    ImageResponse,
    Usage,
)


def mock_embedding(model: str, mock_response: list[float] | None):
    if mock_response is None:
        mock_response = [0.0] * 1536
    elif mock_response == "error":
        raise Exception("Mock error")
    return EmbeddingResponse(
        model=model,
        data=[Embedding(embedding=mock_response, index=0, object="embedding")],
        usage=Usage(prompt_tokens=10, completion_tokens=0),
    )


def mock_image_generation(model: str, mock_response: str):
    return ImageResponse(
        data=[ImageObject(url=mock_response)],
    )

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. If you want a successful mock, pass a list of floats or None (defaults to 1536 zeros) instead of 'error'.
  2. If testing failure paths, catch the exception: pytest.raises(Exception, match='Mock error').
  3. Search your code/config for mock_response='error' leaking out of test fixtures.

Example fix

// before
resp = litellm.embedding(model='text-embedding-3-small', input=['hi'], mock_response='error')

# after
resp = litellm.embedding(model='text-embedding-3-small', input=['hi'], mock_response=[0.1]*1536)
Defensive patterns

Strategy: try-catch

Validate before calling

def is_mock_error_requested(mock_response) -> bool:
    return mock_response == 'error'

Try / catch

with pytest.raises(Exception, match='Mock error'):
    litellm.embedding(model='text-embedding-3-small', input=['x'], mock_response='error')

Prevention

When it happens

Trigger: Calling litellm.embedding(..., mock_response='error'); router/proxy tests that deliberately trip failures; accidentally passing 'error' as mock_response when it was meant as real content.

Common situations: Integration test suites for retry/fallback logic; CI smoke tests asserting error propagation; copy-paste of test fixtures into production code paths.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/2464835836df93d0. Report an issue: GitHub.