{"record":{"id":"8f31a9d740abe37b","repo":"spring-projects/spring-ai","slug":"maximum-of-8-skills-per-request-provided","errorCode":null,"errorMessage":"Maximum of 8 skills per request. Provided: ","messagePattern":"Maximum of 8 skills per request\\. Provided: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicSkillContainer.java","lineNumber":40,"sourceCode":"import java.util.Map;\n\nimport org.springframework.util.Assert;\n\n/**\n * Container for Claude Skills in a chat completion request. Maximum of 8 skills per\n * request.\n *\n * @author Soby Chacko\n */\npublic class AnthropicSkillContainer {\n\n\tprivate final List<AnthropicSkillRecord> skills;\n\n\tpublic AnthropicSkillContainer(List<AnthropicSkillRecord> skills) {\n\t\tAssert.notNull(skills, \"Skills list cannot be null\");\n\t\tAssert.notEmpty(skills, \"Skills list cannot be empty\");\n\t\tif (skills.size() > 8) {\n\t\t\tthrow new IllegalArgumentException(\"Maximum of 8 skills per request. Provided: \" + skills.size());\n\t\t}\n\t\tthis.skills = Collections.unmodifiableList(new ArrayList<>(skills));\n\t}\n\n\tpublic List<AnthropicSkillRecord> getSkills() {\n\t\treturn this.skills;\n\t}\n\n\t/**\n\t * Convert to a list of maps suitable for JSON serialization via\n\t * {@code JsonValue.from(Map.of(\"skills\", container.toSkillsList()))}.\n\t * @return list of skill maps with type, skill_id, and version keys\n\t */\n\tpublic List<Map<String, Object>> toSkillsList() {\n\t\treturn this.skills.stream().map(AnthropicSkillRecord::toJsonMap).toList();\n\t}\n\n\tpublic static Builder builder() {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicSkillContainer.java#L22-L58","documentation":"AnthropicSkillContainer's constructor enforces the Anthropic API limit of at most 8 skills per request and also requires the list to be non-null and non-empty. Passing more than 8 AnthropicSkillRecord entries throws IllegalArgumentException with the actual size appended to the message.","triggerScenarios":"Creating new AnthropicSkillContainer(skillList) where skillList.size() > 8; programmatically accumulating skill records from configuration or discovery and passing the whole list in one request.","commonSituations":"Loading all skills from a directory or config and hitting the 8-skill API cap; aggregating per-team skill definitions without a global limit; test fixtures with many skills.","solutions":["Reduce the list to at most 8 skills before constructing the container (prioritize the most relevant ones).","Split work into multiple requests, each with <= 8 skills, if all skills are genuinely needed.","Add an application-level guard or config validation that fails early with a clear message when more than 8 skills are configured.","Check for accidental duplicate skill registrations inflating the list size."],"exampleFix":"// before\nnew AnthropicSkillContainer(allSkills); // allSkills.size() == 12\n// after\nnew AnthropicSkillContainer(allSkills.stream().limit(8).toList());","handlingStrategy":"validation","validationCode":"if (skills == null || skills.isEmpty()) throw new IllegalArgumentException(\"At least one skill required\");\nif (skills.size() > 8) throw new IllegalArgumentException(\"Anthropic allows at most 8 skills, got \" + skills.size());","typeGuard":null,"tryCatchPattern":"try {\n    container = new AnthropicSkillContainer(selectedSkills);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Maximum of 8 skills\")) {\n        container = new AnthropicSkillContainer(selectedSkills.subList(0, 8));\n    } else throw e;\n}","preventionTips":["Cap skill selection to 8 in configuration loading code.","Deduplicate skills before constructing the container.","Split large skill sets across multiple requests if all are needed."],"tags":["java","spring-ai","anthropic","skills","limit-exceeded"],"backgroundTag":"value-out-of-range","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"}