Freigeben über

The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.

Matthias 20 Zuverlässigkeitspunkte
2026-05-07T07:31:17.47+00:00

Recently, we started receiving a lot of cut-off responses from GPT-5.* models on Azure. The model starts responding as normal, but then the stream suddenly ends with the message.

{
    "type": "error",
    "error": {
      "type": "model_error",
      "code": null,
      "headers": {
        "azureml-ms-model-functionality-response": "HarmonyAgent UnrecoverableError:"
      },
      "message": "The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently. For more information, please see https://aka.ms/model-error Please include the request ID 
      "param": null
    },
    "sequence_number": 355
  },

through experiments, we could narrow it down and believe the cause is a complex email regex in a tool schema like this


              "to": {
                "description": "Recipient email addresses. Only include if explicitly mentioned by the user; otherwise leave empty so the user fills in recipients in their mail client.",
                "maxItems": 20,
                "type": "array",
                "items": {
                  "type": "string",
                  "format": "email",
                  "pattern": "^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$"
                }               }              

Since we don't have a good way of confirming this directly, I'd appreciate it if someone from microsoft can look into the error code and tell us what's the root cause

Foundry Tools
Foundry Tools

Früher bekannt als Azure-KI-Dienste oder Azure Cognitive Services; eine einheitliche Sammlung vordefinierter KI-Funktionen innerhalb der Microsoft Foundry-Plattform


Antwort, die vom Frageautor angenommen wurde

Karnam Venkata Rajeswari 3,835 Zuverlässigkeitspunkte Externe Microsoft-Mitarbeiter Moderator
2026-05-12T03:38:32.3433333+00:00

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

  1. negative lookaheads
  2. strict anchors (^ / $)
  3. nested quantifiers
  4. 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

  1. the response starts normally,
  2. partial output is generated successfully,
  3. and the stream stops once validation can no longer continue.

Please check if the following steps help -

  1. Simplifying or remove the custom regex pattern
    1. 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.
    2. If additional validation is required, consider a minimal pattern such as ^[^@\s]+@[^@\s]+\.[^@\s]+$
  2. 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.
  3. 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.
  4. Reducing overall schema complexity by simplifying nested objects, restrictive constraints or large tool definitions can improve generation stability.

Additional diagnostic checks include

  1. Removing only the "pattern" field while keeping "format": "email"
  2. Replacing the regex with a minimal validation pattern
  3. Comparing streaming versus non‑streaming behavior
  4. Testing across different model or API versions
  5. 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

Please let us know if the above suggestions were helpful

Thank you

War diese Antwort hilfreich?

Eine Person fand diese Antwort hilfreich.
0 Kommentare Keine Kommentare

1 zusätzliche Antwort

Sortieren nach: Am hilfreichsten
  1. Matthias 20 Zuverlässigkeitspunkte
    2026-05-12T07:27:46.0366667+00:00

    Hi Karnam,

    thanks for the insights!
    I can indeed confirm that using a simpler pattern and then applying validation on our side after the response is streamed mitigated the error.
    Thanks for confirming that this is known, and our workaround is the recommended path.

    War diese Antwort hilfreich?

    0 Kommentare Keine Kommentare

Ihre Antwort

Antworten können von Fragestellenden als „Angenommen“ und von Moderierenden als „Empfohlen“ gekennzeichnet werden, wodurch Benutzende wissen, dass diese Antwort das Problem des Fragestellenden gelöst hat.