Google Gemini responseSchema 400 fixer

Resolve 400 INVALID_ARGUMENT failures by inlining non-cyclic $ref definitions, converting type arrays to nullable: true, and stripping unsupported string formats.

Presets
Detected: JSON
{
  "generationConfig": {
    "responseMimeType": "application/json",
    "responseSchema": {
      "title": "CreateSupportTicket",
      "description": "File a customer support ticket with optional billing context.",
      "type": "object",
      "properties": {
        "subject": {
          "type": "string",
          "description": "(minLength: 5) (maxLength: 120)"
        },
        "priority": {
          "type": "string",
          "enum": [
            "low",
            "normal",
            "urgent"
          ]
        },
        "contact": {
          "type": "object",
          "properties": {
            "email": {
              "type": "string",
              "description": "(format: email)"
            },
            "locale": {
              "type": "string",
              "description": "(minLength: 2) (maxLength: 5)"
            }
          },
          "required": [
            "email"
          ]
        },
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "(uniqueItems: true)"
        },
        "notes": {
          "type": "string",
          "nullable": true
        }
      },
      "required": [
        "subject",
        "contact"
      ]
    }
  }
}

Gemini responseSchema vs responseJsonSchema

Gemini supports two structured output fields: the legacy OpenAPI 3.0 subset (responseSchema) and the modern JSON Schema field (responseJsonSchema). Never send both in the same request.

Keyword / feature responseSchema (Legacy OpenAPI 3.0) responseJsonSchema (Modern)
$defs and $ref Rejected with 400. SchemaGate inlines acyclic refs and blocks cycles with exact cycle path. Supported, including recursive schemas when nullable.
additionalProperties Rejected with 400. Stripped automatically. Accepted.
Nullable types Requires nullable: true; rejects type: ["string", "null"]. Accepts JSON Schema type arrays and anyOf.
String format Only enum and date-time allowed; others like email or uuid return 400. Accepted (some formats advisory only).
Empty "" in enum Rejected with 400. Stripped with error diagnostic. Avoid empty enum values across providers.