From edf076bf84a7b2771dd6c8913b315314cd023fe7 Mon Sep 17 00:00:00 2001 From: Shreyas-Microsoft Date: Mon, 18 May 2026 19:08:31 +0530 Subject: [PATCH] fix(processor): retry 'model produced invalid content' and bump ResultGenerator max_tokens (Bug #43771) Two-part fix for the Design step failure 'The model produced invalid content': 1. Add 'model produced invalid content' / 'invalid content' to the transient-error patterns recognised by _looks_like_rate_limit so that AzureOpenAIResponseClientWithRetry retries instead of failing. 2. Increase the ResultGenerator agent's max_tokens from 12_000 to 25_000 in OrchestratorBase to prevent truncation of large nested JSON schemas (the underlying cause of the 'invalid content' error). ADO #43771 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../libs/agent_framework/azure_openai_response_retry.py | 8 ++++++++ src/processor/src/libs/base/orchestrator_base.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/processor/src/libs/agent_framework/azure_openai_response_retry.py b/src/processor/src/libs/agent_framework/azure_openai_response_retry.py index 48b829b3..42f6422e 100644 --- a/src/processor/src/libs/agent_framework/azure_openai_response_retry.py +++ b/src/processor/src/libs/agent_framework/azure_openai_response_retry.py @@ -78,6 +78,14 @@ def _looks_like_rate_limit(error: BaseException) -> bool: if isinstance(status, int) and 500 <= status < 600: return True + # "The model produced invalid content" is a transient error from Azure OpenAI + # when the model output fails content/schema validation — worth retrying. + if any( + s in msg + for s in ["model produced invalid content", "invalid content"] + ): + return True + cause = getattr(error, "__cause__", None) if cause and cause is not error: return _looks_like_rate_limit(cause) diff --git a/src/processor/src/libs/base/orchestrator_base.py b/src/processor/src/libs/base/orchestrator_base.py index 46dce8c6..fbcb39e2 100644 --- a/src/processor/src/libs/base/orchestrator_base.py +++ b/src/processor/src/libs/base/orchestrator_base.py @@ -188,10 +188,12 @@ async def create_agents( ) elif agent_info.agent_name == "ResultGenerator": # Structured JSON generation; deterministic and bounded. + # Use 25_000 to prevent truncation of complex nested JSON schemas + # which causes "model produced invalid content" errors. builder = ( builder .with_temperature(0.0) - .with_max_tokens(12_000) + .with_max_tokens(25_000) .with_tool_choice("none") )