{"record":{"id":"1cf8a9c51804093f","repo":"github/copilot-sdk","slug":"schema-cannot-be-combined-with-defaultvalue-expr","errorCode":null,"errorMessage":"schema cannot be combined with defaultValue — express defaults inside the schema if needed","messagePattern":"schema cannot be combined with defaultValue — express defaults inside the schema if needed","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/tool/Param.java","lineNumber":62,"sourceCode":"        this.type = Objects.requireNonNull(type, \"type\");\n        this.name = requireNonBlank(name, \"name\");\n        this.description = requireNonBlank(description, \"description\");\n        this.defaultValue = defaultValue == null ? \"\" : defaultValue;\n        this.schema = schema == null ? \"\" : schema;\n        this.required = required;\n\n        if (this.required && !this.defaultValue.isEmpty()) {\n            throw new IllegalArgumentException(\"required=true cannot be combined with a non-empty defaultValue\");\n        }\n\n        if (!this.schema.isEmpty()) {\n            String trimmed = this.schema.trim();\n            if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) {\n                throw new IllegalArgumentException(\n                        \"schema must be a valid JSON object string (must start with '{' and end with '}')\");\n            }\n            if (!this.defaultValue.isEmpty()) {\n                throw new IllegalArgumentException(\n                        \"schema cannot be combined with defaultValue — express defaults inside the schema if needed\");\n            }\n        }\n\n        validateDefaultValue(type, this.defaultValue);\n    }\n\n    /**\n     * Creates a required parameter with no default value.\n     *\n     * @param <T>\n     *            the parameter type\n     * @param type\n     *            the Java class of the parameter\n     * @param name\n     *            the wire name sent to the model (must not be blank)\n     * @param description\n     *            a human-readable description (must not be blank)","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/tool/Param.java#L44-L80","documentation":"A Param's schema and defaultValue are mutually exclusive: when a JSON object schema is supplied, any default value must be expressed inside the schema itself. If both a non-empty schema and a non-empty defaultValue are set, the constructor throws this IllegalArgumentException (em-dash in message). This keeps the schema the single source of truth for defaults.","triggerScenarios":"new Param(..., defaultValue=\"x\", schema=\"{...}\") — any combination of non-empty schema plus non-empty defaultValue.","commonSituations":"Migrating existing params to schema-based definitions while leaving the old defaultValue in place; mixing two configuration styles when declaring Copilot tool parameters.","solutions":["Remove the defaultValue and declare the default in the schema (e.g. via a \"default\" keyword) if supported.","Drop the schema if the defaultValue-based declaration style is what you want.","Grep tool declarations for params setting both fields and fix them before deployment."],"exampleFix":"// before\nnew Param(\"q\", \"desc\", Type.STRING, \"hello\", false, \"{\\\"type\\\":\\\"object\\\"}\");\n// after\nnew Param(\"q\", \"desc\", Type.STRING, null, false, \"{\\\"type\\\":\\\"object\\\"}\");","handlingStrategy":"validation","validationCode":"static Param schemaOnlyParam(String name, String desc, Class<?> type, String schema) {\n    if (schema != null && !schema.isEmpty())\n        return new Param(name, desc, type, null, false, schema); // defaults live in the schema\n    return new Param(name, desc, type, null, false, null);\n}","typeGuard":null,"tryCatchPattern":"try {\n    new Param(name, desc, type, def, false, schema);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"schema cannot be combined with defaultValue\")) {\n        // choose one style: either schema (put default inside) or defaultValue\n    }\n    throw e;\n}","preventionTips":["Pick one default-expression style per codebase: schema-embedded or defaultValue, never both.","During migration to schemas, strip old defaultValue fields in the same change.","Lint tool declarations for params that set both fields."],"tags":["validation","tool-parameters","conflicting-options","json-schema"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}