{"record":{"id":"9cfbbbacf4574567","repo":"BerriAI/litellm","slug":"run-status-error-msg","errorCode":null,"errorMessage":"Run {status}: {error_msg}","messagePattern":"Run \\{status\\}: \\{error_msg\\}","errorType":"http","errorClass":"AzureAIAgentsError","httpStatus":500,"severity":"error","filePath":"litellm/llms/azure_ai/agents/handler.py","lineNumber":344,"sourceCode":"        response = make_request(\"POST\", self._build_runs_url(api_base, thread_id, api_version), run_payload)\n        self._check_response(response, [200, 201], \"Failed to create run\")\n        run_id: Final = response.json()[\"id\"]\n        verbose_logger.debug(\"Created run: %s\", run_id)\n\n        # Step 4: Poll for completion\n        status_url: Final = self._build_run_status_url(api_base, thread_id, run_id, api_version)\n        for _ in range(self.config.MAX_POLL_ATTEMPTS):\n            response = make_request(\"GET\", status_url)\n            self._check_response(response, [200], \"Failed to get run status\")\n\n            status = response.json().get(\"status\")\n            verbose_logger.debug(\"Run status: %s\", status)\n\n            if status == \"completed\":\n                break\n            elif status in [\"failed\", \"cancelled\", \"expired\"]:\n                error_msg = response.json().get(\"last_error\", {}).get(\"message\", \"Unknown error\")\n                raise AzureAIAgentsError(status_code=500, message=f\"Run {status}: {error_msg}\")\n\n            time.sleep(self.config.POLL_INTERVAL_SECONDS)\n        else:\n            raise AzureAIAgentsError(status_code=408, message=\"Run timed out waiting for completion\")\n\n        # Step 5: Get messages\n        response = make_request(\"GET\", self._build_list_messages_url(api_base, thread_id, api_version))\n        self._check_response(response, [200], \"Failed to get messages\")\n\n        content, annotations = self._extract_content_from_messages(response.json())\n        return thread_id, content, annotations\n\n    # -------------------------------------------------------------------------\n    # Async Completion\n    # -------------------------------------------------------------------------\n    async def acompletion(\n        self,\n        model: str,","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/azure_ai/agents/handler.py#L326-L362","documentation":"For non-streaming Azure AI Agents completions, LiteLLM creates a run on a thread and polls its status. If the Azure run reports a terminal status of 'failed', 'cancelled', or 'expired' instead of 'completed', it raises AzureAIAgentsError with status_code 500 and a message combining the run status with last_error.message from the run resource. The root cause lives in the Azure agent run (tool errors, content filter, quota), not in LiteLLM.","triggerScenarios":"Agent run whose tool call raised on the Azure side (failed); run cancelled by another client or the Foundry portal (cancelled); thread/run exceeded Azure's retention window so the run expired (expired). Typical with agents that call user-defined tools, code interpreter, or hit content-filter policies.","commonSituations":"Misconfigured tool definitions on the agent; agent instructed to call a function you never wired on Azure; run queued longer than the expiry window under load; someone cancels the run in the portal while debugging; OpenAI tool schema changes after a model upgrade on the Azure side.","solutions":["Inspect the error text — it is Azure's last_error.message and names the actual failure (e.g. which tool failed).","For 'failed': test the same agent in Azure AI Foundry playground; fix tool definitions/instructions there, LiteLLM only relays the failure.","For 'cancelled': check whether another process or person cancelled the run; retry if unintended.","For 'expired': reduce run latency (smaller inputs, faster tools) or re-submit the run on a fresh thread."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    thread_id, content, annotations = handler_completion(...)\nexcept Exception as e:\n    if type(e).__name__ == 'AzureAIAgentsError' and str(e).startswith(('Run failed', 'Run cancelled', 'Run expired')):\n        handle_run_outcome(e.message)  # surface Azure last_error to caller / alerting\n    raise","preventionTips":["Test every agent tool in the Foundry playground before wiring it into production calls.","Keep run inputs small enough that tools finish well inside your latency budget.","Tag cancelled runs to distinguish user action from Azure-side failure in logs."],"tags":["azure","agents","run-status","polling","tool-failure"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}