iflytek/astron-agent · error · BusinessException

TOOLBOX_NOT_NUMBER_TYPE

TOOLBOX_NOT_NUMBER_TYPE

Error message

BusinessException(ResponseEnum.TOOLBOX_NOT_NUMBER_TYPE)

What it means

Thrown by ToolBoxService when converting an array element whose declared parameter type is NUMBER: Double.valueOf(String.valueOf(value)) failed because the value string is not parseable as a double. The service enforces strict runtime type matching between a tool's declared input schema and the actual values supplied by the caller.

Solutions

  1. Fix the caller to send a valid numeric value for every NUMBER-typed array element (plain decimal, no thousand separators or units).
  2. Sanitize/convert values before the call (e.g. parse client-side with Number(value) and reject NaN, trim whitespace).
  3. If the values are legitimately non-numeric, correct the tool's schema so the array item type is STRING instead of NUMBER.
  4. Check logs (ToolBoxService logs the offending value) to identify which field carried the bad value.

Example fix

// before
{"items": ["12.5", "not-a-number"]}
// after
{"items": [12.5, 3.14]}
Defensive patterns

Strategy: validation

Validate before calling

boolean isNumber(Object v) {
    if (v == null) return false;
    try { Double.parseDouble(String.valueOf(v).trim()); return true; }
    catch (NumberFormatException e) { return false; }
}
// call before API: if (!items.stream().allMatch(this::isNumber)) throw ...;

Type guard

boolean isNumericString(Object v) {
    return v instanceof Number
        || (v instanceof String s && s.trim().matches("-?\\d+(\\.\\d+)?([eE][+-]?\\d+)?"));
}

Try / catch

try {
    toolBoxService.callTool(...);
} catch (BusinessException e) {
    if ("TOOLBOX_NOT_NUMBER_TYPE".equals(e.getCode())) {
        // report which array element is non-numeric and fix payload
    }
}

Prevention

When it happens

Trigger: Calling a toolbox tool API whose schema declares an array item of type NUMBER while the caller supplies an array element whose string form is not a valid double (e.g. "abc", empty string, null, or "1.2.3").

Common situations: Frontend sends user-entered text for a numeric field; JSON numbers arrive as strings with locale formatting ("1,234.5"); upstream workflow passes empty or null values for optional numeric array items.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/d836970a2bae424a. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/tool/ToolBoxService.java:1388

                case OBJECT:
                    JSONObject obj = recurGenRunParam(item.getChildren());
                    jsonObject.put(item.getName(), obj);
                    break;
                case ARRAY:
                    JSONArray array = new JSONArray();
                    for (WebSchemaItem childItem : item.getChildren()) {
                        if (OBJECT.equals(childItem.getType())) {
                            JSONObject objItem = recurGenRunParam(childItem.getChildren());
                            array.add(objItem);
                        } else {
                            Object value = childItem.getDft();
                            switch (childItem.getType()) {
                                case NUMBER:
                                    try {
                                        array.add(Double.valueOf(String.valueOf(value)));
                                    } catch (Exception e) {
                                        log.error(value + " is not Number type");
                                        throw new BusinessException(ResponseEnum.TOOLBOX_NOT_NUMBER_TYPE);
                                    }
                                    break;
                                case INTEGER:
                                    try {
                                        array.add(Long.valueOf(String.valueOf(value)));
                                    } catch (Exception e) {
                                        log.error(value + " is not Integer type");
                                        throw new BusinessException(ResponseEnum.TOOLBOX_NOT_INTEGER_TYPE);
                                    }
                                    break;
                                case BOOLEAN:
                                    try {
                                        array.add(Boolean.valueOf(String.valueOf(value)));
                                    } catch (Exception e) {
                                        log.error(value + " is not Boolean type");
                                        throw new BusinessException(ResponseEnum.TOOLBOX_NOT_BOOLEAN_TYPE);
                                    }
                                    break;

View on GitHub (pinned to 5e758547a8)