Skip to content

Bug: Invalid JSON Schema Generated Due to Unsupported Regex Lookaround in fileKey Pattern On GPT 5.5 #31996

@fresp

Description

@fresp

Description

Summary

When using OpenCode with an OpenAI-compatible provider, requests fail before reaching the model with the following error:

Invalid JSON schema: regex lookaround is not supported.
Found at $.properties.fileKey.pattern

This appears to be caused by OpenCode generating a JSON Schema containing a regex pattern with lookaround assertions ((?=...), (?!...), (?<=...), or (?<!...)).

Many JSON Schema validators used by OpenAI-compatible providers do not support regex lookarounds, causing schema validation to fail before inference begins.


Environment

  • OpenCode Version: Latest
  • Provider: OpenAI-compatible API
  • Model: GPT-5.5
  • OS: Linux

Steps to Reproduce

  1. Configure OpenCode with an OpenAI-compatible provider.
  2. Start a new session.
  3. Send a simple prompt:
hai
  1. Observe the response.

Actual Result

OpenCode immediately returns:

Invalid JSON schema: regex lookaround is not supported.
Found at $.properties.fileKey.pattern

No request reaches the model.


Expected Result

OpenCode should either:

  • Generate a JSON Schema compatible with common Structured Output validators, or
  • Detect unsupported schema features and gracefully fall back to a non-structured-output mode.

The request should not fail before model execution.


Analysis

The error points to:

$.properties.fileKey.pattern

which suggests OpenCode is generating a schema similar to:

{
  "type": "object",
  "properties": {
    "fileKey": {
      "type": "string",
      "pattern": "..."
    }
  }
}

The generated regex appears to contain lookaround assertions.

While lookarounds are supported by some regex engines, they are not universally supported by JSON Schema validators used by OpenAI-compatible APIs and structured output implementations.

As a result, schema validation fails before the request can be processed by the model.


Suggested Fix

  • Avoid generating regex patterns that rely on lookaround assertions.
  • Replace lookaround-based validation with schema-compatible alternatives.
  • Add a fallback path when structured output schema validation fails.
  • Consider validating generated schemas against common OpenAI-compatible implementations before sending requests.

Additional Context

The issue is reproducible with a simple prompt and appears unrelated to the model itself.

Based on the error message, the failure occurs during schema validation rather than inference.

This may affect any OpenAI-compatible provider that enforces JSON Schema validation and does not support regex lookaround syntax.

Plugins

No response

OpenCode version

1.17.4

Steps to reproduce

No response

Screenshot and/or share link

Image

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions