Früher bekannt als Azure-KI-Dienste oder Azure Cognitive Services; eine einheitliche Sammlung vordefinierter KI-Funktionen innerhalb der Microsoft Foundry-Plattform
Hello Matthias,
Welcome to Microsoft Q&A .Thank you for reaching out to us.
Thank you for your patience while we were working on this.
Based on the observed behavior , the error is consistent with a runtime structured‑output validation failure during tool/function‑call generation when using GPT‑5. models with streaming enabled.
As the responses begin streaming successfully and then terminate abruptly with:
- “The model produced invalid content”
- “HarmonyAgent UnrecoverableError”
validate that the complex email‑validation regex defined in the tool schema is contributing to this behavior.Relaxing or removing the regex and handling strict validation outside the model can help resolve the error.
The current schema already includes "format": "email" along with a highly restrictive custom regex pattern that uses advanced constructs such as
- negative lookaheads
- strict anchors (^ / $)
- nested quantifiers
- tight character‑level constraints
While the regex itself may be valid in standard regex engines, GPT‑5 models apply incremental runtime validation while generating structured tool outputs. During streaming generation, the model may temporarily emit intermediate tokens that do not satisfy a highly restrictive regex, even if the final value would otherwise be valid. When this occurs, the validation layer encounters an unrecoverable failure, terminates the stream, and returns the observed model_error.
This explains the observed behavior that
- the response starts normally,
- partial output is generated successfully,
- and the stream stops once validation can no longer continue.
Please check if the following steps help -
- Simplifying or remove the custom regex pattern
- As an initial test, remove only the "pattern" field while keeping "format": "email". This change alone has been shown to prevent stream termination in similar cases.
- If additional validation is required, consider a minimal pattern such as
^[^@\s]+@[^@\s]+\.[^@\s]+$
- Please avoid advanced regex assertions as constructs such as negative lookaheads (?!...) and tightly anchored expressions increase complexity during structured‑output validation and should be avoided.
- Please consider performing strict validation on the application‑side as validating values after generation in application code is generally more stable than enforcing highly restrictive patterns inside the tool schema.
- Reducing overall schema complexity by simplifying nested objects, restrictive constraints or large tool definitions can improve generation stability.
Additional diagnostic checks include
- Removing only the "pattern" field while keeping "format": "email"
- Replacing the regex with a minimal validation pattern
- Comparing streaming versus non‑streaming behavior
- Testing across different model or API versions
- Validating the schema separately using an external JSON Schema validator
The above checks validate successful external schema which confirms syntax correctness. However, runtime behavior during streaming generation may still vary depending on schema complexity.
The following references might be helpful , please check them out
- Use the Azure OpenAI Responses API - Microsoft Foundry | Microsoft Learn
- How to use function calling with Azure OpenAI in Microsoft Foundry Models - Microsoft Foundry | Microsoft Learn
Please let us know if the above suggestions were helpful
Thank you