{"record":{"id":"2464835836df93d0","repo":"BerriAI/litellm","slug":"mock-error","errorCode":null,"errorMessage":"Mock error","messagePattern":"Mock error","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/mock_functions.py","lineNumber":14,"sourceCode":"from ..types.utils import (\n    Embedding,\n    EmbeddingResponse,\n    ImageObject,\n    ImageResponse,\n    Usage,\n)\n\n\ndef mock_embedding(model: str, mock_response: list[float] | None):\n    if mock_response is None:\n        mock_response = [0.0] * 1536\n    elif mock_response == \"error\":\n        raise Exception(\"Mock error\")\n    return EmbeddingResponse(\n        model=model,\n        data=[Embedding(embedding=mock_response, index=0, object=\"embedding\")],\n        usage=Usage(prompt_tokens=10, completion_tokens=0),\n    )\n\n\ndef mock_image_generation(model: str, mock_response: str):\n    return ImageResponse(\n        data=[ImageObject(url=mock_response)],\n    )\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/mock_functions.py#L1-L26","documentation":"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.","triggerScenarios":"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.","commonSituations":"Integration test suites for retry/fallback logic; CI smoke tests asserting error propagation; copy-paste of test fixtures into production code paths.","solutions":["If you want a successful mock, pass a list of floats or None (defaults to 1536 zeros) instead of 'error'.","If testing failure paths, catch the exception: pytest.raises(Exception, match='Mock error').","Search your code/config for mock_response='error' leaking out of test fixtures."],"exampleFix":"// before\nresp = litellm.embedding(model='text-embedding-3-small', input=['hi'], mock_response='error')\n\n# after\nresp = litellm.embedding(model='text-embedding-3-small', input=['hi'], mock_response=[0.1]*1536)","handlingStrategy":"try-catch","validationCode":"def is_mock_error_requested(mock_response) -> bool:\n    return mock_response == 'error'","typeGuard":null,"tryCatchPattern":"with pytest.raises(Exception, match='Mock error'):\n    litellm.embedding(model='text-embedding-3-small', input=['x'], mock_response='error')","preventionTips":["Keep mock_response='error' strictly in test fixtures that assert failures.","Grep production configs for leftover mock_response settings after testing."],"tags":["mocking","testing","embeddings","intentional-error"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}