{"record":{"id":"2bb2aaf8d24be473","repo":"spring-projects/spring-ai","slug":"unsupported-response-format-type","errorCode":null,"errorMessage":"Unsupported response format type: ","messagePattern":"Unsupported response format type: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatModel.java","lineNumber":795,"sourceCode":"\t\t\t\t\t\t.builder();\n\t\t\t\t\tjsonSchemaBuilder.name(\"json_schema\");\n\t\t\t\t\tBoolean strict = responseFormat.getStrict();\n\t\t\t\t\tjsonSchemaBuilder.strict(strict != null ? strict : true);\n\n\t\t\t\t\tResponseFormatJsonSchema.JsonSchema.Schema schema = objectMapper.readValue(jsonSchemaString,\n\t\t\t\t\t\t\tResponseFormatJsonSchema.JsonSchema.Schema.class);\n\n\t\t\t\t\tjsonSchemaBuilder.schema(schema);\n\n\t\t\t\t\tbuilder.responseFormat(\n\t\t\t\t\t\t\tResponseFormatJsonSchema.builder().jsonSchema(jsonSchemaBuilder.build()).build());\n\t\t\t\t}\n\t\t\t\tcatch (Exception e) {\n\t\t\t\t\tthrow new IllegalArgumentException(\"Failed to parse JSON schema: \" + jsonSchemaString, e);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported response format type: \" + responseFormat.getType());\n\t\t\t}\n\t\t}\n\t\tif (requestOptions.getSeed() != null) {\n\t\t\tbuilder.seed(requestOptions.getSeed());\n\t\t}\n\t\tif (requestOptions.getStop() != null && !requestOptions.getStop().isEmpty()) {\n\t\t\tif (requestOptions.getStop().size() == 1) {\n\t\t\t\tbuilder.stop(ChatCompletionCreateParams.Stop.ofString(requestOptions.getStop().get(0)));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tbuilder.stop(ChatCompletionCreateParams.Stop.ofStrings(requestOptions.getStop()));\n\t\t\t}\n\t\t}\n\t\tif (requestOptions.getTemperature() != null) {\n\t\t\tbuilder.temperature(requestOptions.getTemperature());\n\t\t}\n\t\tif (requestOptions.getTopP() != null) {\n\t\t\tbuilder.topP(requestOptions.getTopP());","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatModel.java#L777-L813","documentation":"createRequest only maps ResponseFormat.Type values TEXT, JSON_OBJECT, and JSON_SCHEMA to OpenAI response_format parameters. If requestOptions.getResponseFormat() has any other ResponseFormat.Type enum value, no mapping exists and this IllegalArgumentException is thrown. The library deliberately fails fast because sending an unmapped response format type would be silently dropped or produce an API error downstream.","triggerScenarios":"Setting a ResponseFormat whose getType() returns a Type value other than TEXT, JSON_OBJECT, or JSON_SCHEMA — typically a custom/extended ResponseFormat implementation or an enum value added in a different library version — and then calling chat()/call()/stream() with those options.","commonSituations":"Using a ResponseFormat type from another model provider's Spring AI module (e.g. a VertexAI or Mistral-specific type) with OpenAiChatOptions; a version skew where a new ResponseFormat.Type constant exists but this OpenAiChatModel doesn't map it yet; a custom ResponseFormat subclass returning its own type.","solutions":["Change the response format type to one of the supported values: ResponseFormat.Type.TEXT, JSON_OBJECT, or JSON_SCHEMA.","For JSON_SCHEMA, also set the jsonSchema string on the ResponseFormat so the JSON_SCHEMA branch succeeds.","Check for version mismatches between spring-ai-openai and spring-ai-core (or other model modules) and align them to the same release so all ResponseFormat.Type values are mapped.","If you need an exotic response_format, pass it via OpenAiChatOptions extraBody/additional properties instead of ResponseFormat."],"exampleFix":"// before\noptions.setResponseFormat(new ResponseFormat(ResponseFormat.Type.ETL, null)); // unknown to OpenAI model\n\n// after\noptions.setResponseFormat(new ResponseFormat(ResponseFormat.Type.JSON_OBJECT, null));\n// or for structured output:\noptions.setResponseFormat(new ResponseFormat(ResponseFormat.Type.JSON_SCHEMA, schemaJson));","handlingStrategy":"type-guard","validationCode":"java.util.EnumSet<ResponseFormat.Type> supported =\n    java.util.EnumSet.of(ResponseFormat.Type.TEXT, ResponseFormat.Type.JSON_OBJECT, ResponseFormat.Type.JSON_SCHEMA);\nif (options.getResponseFormat() != null && !supported.contains(options.getResponseFormat().getType())) {\n    throw new IllegalStateException(\"ResponseFormat type not supported by OpenAiChatModel: \" + options.getResponseFormat().getType());\n}","typeGuard":"boolean isSupportedResponseFormat(ResponseFormat rf) {\n    return rf == null || rf.getType() == ResponseFormat.Type.TEXT\n        || rf.getType() == ResponseFormat.Type.JSON_OBJECT\n        || rf.getType() == ResponseFormat.Type.JSON_SCHEMA;\n}","tryCatchPattern":"try {\n    return chatModel.call(prompt);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unsupported response format type:\")) {\n        prompt.getOptions().setResponseFormat(new ResponseFormat(ResponseFormat.Type.TEXT, null));\n        return chatModel.call(prompt);\n    }\n    throw e;\n}","preventionTips":["Only construct ResponseFormat with ResponseFormat.Type.TEXT, JSON_OBJECT, or JSON_SCHEMA.","Don't reuse ResponseFormat objects/types from other Spring AI model modules with OpenAiChatOptions.","Align spring-ai-openai and spring-ai-core versions so all enum values are mapped.","Centralize response-format construction in one factory method that whitelists supported types."],"tags":["openai","spring-ai","response-format","unsupported-value","illegal-argument"],"backgroundTag":"unsupported-enum-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}