{"record":{"id":"ef767a5a86bb17da","repo":"spring-projects/spring-ai","slug":"only-outputtype-or-outputjsonschema-can-be-set-no","errorCode":null,"errorMessage":"Only outputType or outputJsonSchema can be set, not both.","messagePattern":"Only outputType or outputJsonSchema can be set, not both\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/advisor/StructuredOutputValidationAdvisor.java","lineNumber":341,"sourceCode":"\t\t * {@link JacksonUtils#getDefaultJsonMapper()}.\n\t\t * @param jsonMapper the JSON mapper\n\t\t * @return this builder\n\t\t */\n\t\tpublic Builder jsonMapper(JsonMapper jsonMapper) {\n\t\t\tthis.jsonMapper = jsonMapper;\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Builds the StructuredOutputValidationAdvisor.\n\t\t * @return a new StructuredOutputValidationAdvisor instance\n\t\t * @throws IllegalArgumentException if neither outputType nor outputJsonSchema is\n\t\t * set, or if both are set\n\t\t */\n\t\tpublic StructuredOutputValidationAdvisor build() {\n\n\t\t\tif (StringUtils.hasText(this.outputJsonSchema) && this.outputType != null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Only outputType or outputJsonSchema can be set, not both.\");\n\t\t\t}\n\n\t\t\tif (!StringUtils.hasText(this.outputJsonSchema) && this.outputType == null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Either outputType or outputJsonSchema must be set.\");\n\t\t\t}\n\n\t\t\tif (this.outputType != null) {\n\t\t\t\tthis.outputJsonSchema = JsonSchemaGenerator.generateForType(this.outputType);\n\t\t\t}\n\n\t\t\treturn new StructuredOutputValidationAdvisor(this.advisorOrder,\n\t\t\t\t\tObjects.requireNonNull(this.outputJsonSchema), this.maxRepeatAttempts, this.jsonMapper);\n\t\t}\n\n\t}\n\n\tprivate record SchemaValidation(boolean success, String errorMessage) {\n","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/advisor/StructuredOutputValidationAdvisor.java#L323-L359","documentation":"StructuredOutputValidationAdvisor.Builder.build() enforces that the output format is specified exactly one way: either outputType (a Java type from which a schema is generated) or outputJsonSchema (an explicit schema string). Setting both is ambiguous and throws IllegalArgumentException('Only outputType or outputJsonSchema can be set, not both.').","triggerScenarios":"Calling .outputType(SomeClass.class) and .outputJsonSchema(\"...\") on the same Builder before build().","commonSituations":"Adding an explicit schema to refine an existing type-based config, merging builder defaults with user-supplied schema, or copy-pasted builder code where both sources of truth were left in place.","solutions":["Remove either the outputType or the outputJsonSchema call — keep one.","If you want the generated schema plus tweaks, keep outputType only, or precompute generateForType(type), edit it, and pass that as outputJsonSchema instead.","Search builder chains in your config for both method calls on the same advisor builder."],"exampleFix":"// before\nStructuredOutputValidationAdvisor.builder()\n    .outputType(MyRecord.class)\n    .outputJsonSchema(schemaString)\n    .build();\n// after\nStructuredOutputValidationAdvisor.builder()\n    .outputType(MyRecord.class)\n    .build();","handlingStrategy":"validation","validationCode":"StructuredOutputValidationAdvisor.Builder b = StructuredOutputValidationAdvisor.builder();\n// ensure only one of the two is ever set in your builder helper\nif (useType) b.outputType(MyRecord.class); else b.outputJsonSchema(schemaString);","typeGuard":null,"tryCatchPattern":"try { advisorBuilder.build(); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Only outputType or outputJsonSchema\")) { /* remove one setter */ } throw e; }","preventionTips":["Wrap builder construction in a helper that sets exactly one output source.","Search advisor builder chains for both outputType and outputJsonSchema calls.","If refining a generated schema, generate it first, edit, then pass only outputJsonSchema."],"tags":["builder","configuration","structured-output","spring-ai"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}