{"record":{"id":"7baa6b63126e85d1","repo":"BerriAI/litellm","slug":"standard-logging-object-not-found-in-kwargs","errorCode":null,"errorMessage":"standard_logging_object not found in kwargs","messagePattern":"standard_logging_object not found in kwargs","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"litellm/integrations/literal_ai.py","lineNumber":168,"sourceCode":"                    \"query\": query,\n                    \"variables\": variables,\n                },\n                headers=self.headers,\n            )\n            if response.status_code >= 300:\n                verbose_logger.error(\"Literal AI Error: %s - %s\", response.status_code, response.text)\n            else:\n                verbose_logger.debug(\"Batch of %s runs successfully created\", len(self.log_queue))\n        except httpx.HTTPStatusError as e:\n            verbose_logger.exception(\"Literal AI HTTP Error: %s - %s\", e.response.status_code, e.response.text)\n        except Exception:\n            verbose_logger.exception(\"Literal AI Layer Error\")\n\n    def _prepare_log_data(self, kwargs, response_obj, start_time, end_time) -> dict:\n        logging_payload: Final[StandardLoggingPayload | None] = kwargs.get(\"standard_logging_object\", None)\n\n        if logging_payload is None:\n            raise ValueError(\"standard_logging_object not found in kwargs\")\n        clean_metadata: Final = logging_payload[\"metadata\"]\n        metadata: Final = kwargs.get(\"litellm_params\", {}).get(\"metadata\", {})\n\n        settings: Final = logging_payload[\"model_parameters\"]\n        messages: Final = logging_payload[\"messages\"]\n        response: Final = logging_payload[\"response\"]\n        choices: list = []\n        if isinstance(response, dict) and \"choices\" in response:\n            choices = response[\"choices\"]\n        message_completion: Final = choices[0][\"message\"] if choices else None\n        prompt_id = None\n        variables = None\n\n        if messages and isinstance(messages, list) and isinstance(messages[0], dict):\n            for message in messages:\n                if literal_prompt := getattr(message, \"__literal_prompt__\", None):\n                    prompt_id = literal_prompt.get(\"prompt_id\")\n                    variables = literal_prompt.get(\"variables\")","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/literal_ai.py#L150-L186","documentation":"Literal AI's logger requires kwargs['standard_logging_object'] (LiteLLM's normalized StandardLoggingPayload) to build its run data; _prepare_log_data raises ValueError when it is None. In the normal litellm pipeline this payload is always created before success callbacks fire, so seeing this means the logging hook was invoked with hand-made or incomplete kwargs.","triggerScenarios":"Unit-testing the LiteralAI logger with synthetic kwargs; calling async_log_success_event/log_success_event directly; middleware or wrappers that strip or replace kwargs before the callback chain; version skew where the payload key moved.","commonSituations":"Custom test harnesses for callback integrations; forks invoking internal logging APIs; upgrading litellm across versions that changed standard_logging_object construction.","solutions":["Route tests through litellm.completion(..., success_callback=['literalai']) so the standard payload is built by the framework","If calling _prepare_log_data directly, include a valid StandardLoggingPayload dict under kwargs['standard_logging_object'] (with metadata, model_parameters, messages, response keys)","Check any custom middleware that mutates kwargs before callbacks and stop it from dropping the key","Align the litellm version between the app and any copied callback code"],"exampleFix":"# before\nawait logger.async_log_success_event(\n    kwargs={\"litellm_params\": {\"metadata\": {}}},  # ValueError\n    response_obj=resp, start_time=t0, end_time=t1,\n)\n\n# after\nkwargs = {\n    \"standard_logging_object\": {\n        \"metadata\": {}, \"model_parameters\": {},\n        \"messages\": [], \"response\": {\"choices\": []},\n    },\n    \"litellm_params\": {\"metadata\": {}},\n}\nawait logger.async_log_success_event(kwargs=kwargs, response_obj=resp, start_time=t0, end_time=t1)","handlingStrategy":"try-catch","validationCode":"def has_standard_logging_payload(kwargs: dict) -> bool:\n    payload = kwargs.get(\"standard_logging_object\")\n    return isinstance(payload, dict) and {\"metadata\", \"messages\", \"response\"} <= set(payload)","typeGuard":null,"tryCatchPattern":"try:\n    data = logger._prepare_log_data(kwargs, response_obj, start, end)\nexcept ValueError as e:\n    if \"standard_logging_object\" in str(e):\n        return  # hook invoked without framework-built payload; skip\n    raise","preventionTips":["Drive logging tests through real completion calls","Never strip standard_logging_object in custom middleware"],"tags":["python","literal-ai","callback","logging","internal-api"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}