{"record":{"id":"94b47104eb3dcd64","repo":"BerriAI/litellm","slug":"messages-is-required","errorCode":null,"errorMessage":"messages is required","messagePattern":"messages is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/completion_extras/litellm_responses_transformation/handler.py","lineNumber":118,"sourceCode":"        return response\n\n    def validate_input_kwargs(self, kwargs: dict) -> ResponsesToCompletionBridgeHandlerInputKwargs:\n        from litellm import LiteLLMLoggingObj\n        from litellm.types.utils import ModelResponse\n\n        typed_kwargs: Final[dict[str, object]] = kwargs\n\n        model: Final = typed_kwargs.get(\"model\")\n        if model is None or not isinstance(model, str):\n            raise ValueError(\"model is required\")\n\n        custom_llm_provider: Final = typed_kwargs.get(\"custom_llm_provider\")\n        if custom_llm_provider is None or not isinstance(custom_llm_provider, str):\n            raise ValueError(\"custom_llm_provider is required\")\n\n        messages: Final = typed_kwargs.get(\"messages\")\n        if messages is None or not isinstance(messages, list):\n            raise ValueError(\"messages is required\")\n\n        optional_params: Final = typed_kwargs.get(\"optional_params\")\n        if optional_params is None or not isinstance(optional_params, dict):\n            raise ValueError(\"optional_params is required\")\n\n        litellm_params: Final = typed_kwargs.get(\"litellm_params\")\n        if litellm_params is None or not isinstance(litellm_params, dict):\n            raise ValueError(\"litellm_params is required\")\n\n        headers: Final = typed_kwargs.get(\"headers\")\n        if headers is None or not isinstance(headers, dict):\n            raise ValueError(\"headers is required\")\n\n        model_response: Final = typed_kwargs.get(\"model_response\")\n        if model_response is None or not isinstance(model_response, ModelResponse):\n            raise ValueError(\"model_response is required\")\n\n        logging_obj: Final = typed_kwargs.get(\"logging_obj\")","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/completion_extras/litellm_responses_transformation/handler.py#L100-L136","documentation":"The bridge requires 'messages' to be a non-None list before transforming a chat-completions request into a Responses API request. The messages list is what gets converted into Responses API input items (message, function_call, function_call_output). A missing, None, or non-list messages value aborts the call up front.","triggerScenarios":"Direct bridge invocation without messages; passing messages as a tuple/generator/SingleMessage dict instead of a list; a custom pipeline that consumed or reassigned the messages variable before forwarding.","commonSituations":"Adapters converting single-prompt APIs to litellm's message format; refactors that changed messages to an iterator; tests with hand-built kwargs.","solutions":["Call litellm.completion(model, messages=[...]) so validation happens upstream with better errors","Ensure messages is a list of dicts each with role and content keys","If you only have a prompt string, wrap it: messages=[{\"role\":\"user\",\"content\":prompt}]","Type-check kwargs before calling the bridge directly"],"exampleFix":"// before\nhandler.completion(model=m, messages=(\"user\", \"hi\"), ...)  # ValueError: messages is required\n\n// after\nhandler.completion(model=m, messages=[{\"role\": \"user\", \"content\": \"hi\"}], ...)","handlingStrategy":"validation","validationCode":"def messages_are_valid(messages) -> bool:\n    return isinstance(messages, list) and all(\n        isinstance(m, dict) and isinstance(m.get(\"role\"), str) for m in messages\n    )","typeGuard":"def is_message_list(messages) -> bool:\n    return isinstance(messages, list)","tryCatchPattern":"try:\n    handler.completion(**kwargs)\nexcept ValueError as e:\n    if \"messages is required\" in str(e):\n        raise TypeError(\"messages must be a list of {role, content} dicts\") from e\n    raise","preventionTips":["Always wrap prompts as messages=[{\"role\":\"user\",\"content\":prompt}]","Normalize tuples/generators to list before forwarding","Assert message-list shape at the edge of your adapter"],"tags":["validation","kwargs","messages","internal-api"],"backgroundTag":"missing-required-argument","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}