{"record":{"id":"5ac1d5729f280251","repo":"spring-projects/spring-ai","slug":"neither-template-nor-resource-is-set-5ac1d5","errorCode":null,"errorMessage":"Neither template nor resource is set","messagePattern":"Neither template nor resource is set","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/SystemPromptTemplate.java","lineNumber":108,"sourceCode":"\t\tpublic Builder renderer(TemplateRenderer renderer) {\n\t\t\tAssert.notNull(renderer, \"renderer cannot be null\");\n\t\t\tthis.renderer = renderer;\n\t\t\treturn this;\n\t\t}\n\n\t\t@Override\n\t\tpublic SystemPromptTemplate build() {\n\t\t\tif (this.template != null && this.resource != null) {\n\t\t\t\tthrow new IllegalArgumentException(\"Only one of template or resource can be set\");\n\t\t\t}\n\t\t\telse if (this.resource != null) {\n\t\t\t\treturn new SystemPromptTemplate(this.resource, this.variables, this.renderer);\n\t\t\t}\n\t\t\telse if (this.template != null) {\n\t\t\t\treturn new SystemPromptTemplate(this.template, this.variables, this.renderer);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalStateException(\"Neither template nor resource is set\");\n\t\t\t}\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":90,"sourceCodeEnd":115,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/spring-ai-model/src/main/java/org/springframework/ai/chat/prompt/SystemPromptTemplate.java#L90-L115","documentation":"SystemPromptTemplate.Builder.build() throws this IllegalStateException when neither a template string nor a Resource was provided, since a system prompt template requires content from one of those sources.","triggerScenarios":"Calling SystemPromptTemplate.builder().build() without calling template(...) or resource(...).","commonSituations":"Config-driven prompt loading where the template file path was null/empty and the setter was skipped; builder reuse across branches where neither branch fired.","solutions":["Call .template(\"...\") or .resource(...) before build().","Validate that a system-prompt source exists in configuration before building.","Add an early guard that fails with a descriptive config error."],"exampleFix":"// before\nSystemPromptTemplate.builder().build();\n// after\nSystemPromptTemplate.builder().template(\"You are a helpful assistant\").build();","handlingStrategy":"validation","validationCode":"if (templateText == null && resource == null) throw new IllegalStateException(\"Provide a template or resource before building SystemPromptTemplate\");","typeGuard":null,"tryCatchPattern":"try { return builder.build(); } catch (IllegalStateException e) { logger.error(\"no system prompt source configured\", e); throw e; }","preventionTips":["Always set a system-prompt source before build()","Validate external template config (non-null path or text) at startup","Provide a default inline system prompt as fallback"],"tags":["builder","missing-template","system-prompt"],"backgroundTag":"missing-required-option","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"}