t8y2/dbx · error · java.lang.IllegalArgumentException

dropIndex requires a string index name or JSON document

Error message

dropIndex requires a string index name or JSON document

What it means

parseDropIndexesValue validates the indexesJson argument for the dropIndex action. When the argument is missing, null, or blank and single=true (dropIndex mode), the agent throws because a dropIndex call must name exactly one index to drop.

Source

Thrown at agents/drivers/mongodb/src/main/java/com/dbx/agent/mongodb/MongoAgent.java:1367

        // options accepted by createIndexes on every supported server.
        definition.remove("v");
        definition.remove("ns");
        definition.remove("buildUUID");
        definition.remove("ready");
        return definition;
    }

    private static Object dropDatabase(JsonObject params) {
        MongoClient c = requireClient();
        String database = params.get("database").getAsString();
        c.getDatabase(database).drop();
        return Collections.singletonMap("ok", true);
    }

    static Object parseDropIndexesValue(String indexesJson, boolean single) {
        if (indexesJson == null || indexesJson.isBlank()) {
            if (single) {
                throw new IllegalArgumentException("dropIndex requires a string index name or JSON document");
            }
            return "*";
        }

        JsonElement value = JsonParser.parseString(indexesJson);
        if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString()) {
            String name = value.getAsString();
            if (name.isBlank()) {
                throw new IllegalArgumentException("Index name is required");
            }
            if (single && "*".equals(name)) {
                throw new IllegalArgumentException("dropIndex does not accept \"*\"; use dropIndexes() or dropIndexes(\"*\") instead");
            }
            if (DEFAULT_ID_INDEX_NAME.equals(name)) {
                throw new IllegalArgumentException("The default MongoDB _id_ index cannot be dropped");
            }
            return name;
        }

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass a non-blank index name string, e.g. "age_1"
  2. Pass a JSON key-pattern document like {"age": 1}
  3. If you intend to drop all indexes, call dropIndexes (with "*") instead

Example fix

// before
agent.execute("dropIndex", Map.of("database", "shop", "collection", "orders")); // no indexes
// after
agent.execute("dropIndex", Map.of(
    "database", "shop",
    "collection", "orders",
    "indexes", "age_1"
));
Defensive patterns

Strategy: validation

Validate before calling

if (indexesJson == null || indexesJson.isBlank()) {
    throw new IllegalArgumentException("dropIndex needs a non-blank index name or JSON document");
}

Type guard

boolean hasDropIndexTarget(String indexesJson) {
    return indexesJson != null && !indexesJson.isBlank();
}

Try / catch

try {
    agent.execute("dropIndex", params);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("requires a string index name")) {
        throw new IllegalStateException("indexes parameter is mandatory for dropIndex", e);
    } else { throw e; }
}

Prevention

When it happens

Trigger: Invoking dropIndex without the indexes parameter, with an empty string, or with whitespace only; calling dropIndex while relying on the batch default "*" which is only allowed for dropIndexes.

Common situations: Omitting the JSON body field in a tool call; wiring a template variable that resolves to ""; copying a dropIndexes() call and renaming only the action name to dropIndex.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/889dc903713ba60f. Report an issue: GitHub.