github/copilot-sdk · error · IllegalArgumentException

Expected boolean at position

Error message

Expected boolean at position <pos>

What it means

The converter's boolean parser only accepts the exact literals 'true' or 'false' at the current position; anything else raises this IllegalArgumentException. It is the strict-JSON equivalent of 'not a valid boolean here'.

Solutions

  1. Replace the value with the lowercase JSON literals true or false
  2. If the source is Python, use json.dumps() instead of str() to serialize dicts
  3. If the value is really a string like "yes", quote it and convert in application code
  4. Check the reported position to find the offending token

Example fix

// before
String json = "{\"enabled\":True}"; // Python-style
// after
String json = "{\"enabled\":true}"; // JSON literal
Defensive patterns

Strategy: validation

Validate before calling

if (json.matches(".*:\\s*(True|TRUE|yes|no|on|off)\\s*[,}\\]].*")) {
    throw new IllegalArgumentException("Non-JSON boolean literal found; use lowercase true/false");
}

Try / catch

try {
    String result = CopilotToolProcessor.jsonToMapOfSource(json);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Expected boolean")) {
        // replace Python/other-language boolean literals with true/false and retry
    }
}

Prevention

When it happens

Trigger: Parsing JSON containing misspelled booleans ('True', 'TRUE', 'yes', '1', 'on') where a boolean is expected, e.g. '{"flag":True}'.

Common situations: JSON hand-built from Python (whose True/False are capitalized) via str()/repr(); shells or configs exporting 'yes'/'no'; string 'true' left unquoted-but-stringified or numeric 0/1 used for booleans.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/f3dd7f6a73a3480b. Report an issue: GitHub.

Appendix: source

Thrown at java/sdk/src/main/java/com/github/copilot/tool/CopilotToolProcessor.java:1089

                value = (value << 4) | digit;
            }
            return (char) value;
        }

        private boolean isAsciiHexDigit(char c) {
            return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
        }

        private String parseBoolean() {
            if (input.startsWith("true", pos)) {
                pos += 4;
                return "true";
            }
            if (input.startsWith("false", pos)) {
                pos += 5;
                return "false";
            }
            throw new IllegalArgumentException("Expected boolean at position " + pos);
        }

        private String parseNull() {
            if (input.startsWith("null", pos)) {
                pos += 4;
                return "(Object) null";
            }
            throw new IllegalArgumentException("Expected null at position " + pos);
        }

        private String parseNumber() {
            int start = pos;
            if (pos < input.length() && input.charAt(pos) == '-') {
                pos++;
            }
            if (pos >= input.length()) {
                throw new IllegalArgumentException("Expected number at position " + start);
            }

View on GitHub (pinned to cd8cf15dc3)