chroma-core/chroma · error · TypeError

limit must be a non-negative integer

Error message

limit must be a non-negative integer

What it means

The `limit` parameter of `collection.delete()` must be a Python int (bools are explicitly rejected because bool subclasses int). A TypeError is raised when limit is a float, string, None-like sentinel, or boolean.

Source

Thrown at chromadb/api/models/CollectionCommon.py:479

            uris=upsert_records["uris"],
        )

    @validation_context("delete")
    def _validate_and_prepare_delete_request(
        self,
        ids: Optional[IDs],
        where: Optional[Where],
        where_document: Optional[WhereDocument],
        limit: Optional[int] = None,
    ) -> DeleteRequest:
        if ids is None and where is None and where_document is None:
            raise ValueError(
                "At least one of ids, where, or where_document must be provided"
            )

        if limit is not None:
            if not isinstance(limit, int) or isinstance(limit, bool):
                raise TypeError("limit must be a non-negative integer")
            if limit < 0:
                raise ValueError("limit must be a non-negative integer")

        if limit is not None and where is None and where_document is None:
            raise ValueError(
                "limit can only be specified when a where or where_document clause is provided"
            )

        # Unpack
        if ids is not None:
            request_ids = cast(IDs, maybe_cast_one_to_many(ids))
        else:
            request_ids = None
        filters = FilterSet(where=where, where_document=where_document)

        # Validate
        if request_ids is not None:
            validate_ids(ids=request_ids)

View on GitHub (pinned to aecdd12c8a)

Solutions

  1. Pass a plain int: `collection.delete(where=..., limit=10)`
  2. Coerce external values first: `limit = int(limit)` (after range-checking)
  3. Ensure you are not accidentally passing a bool (e.g. a parsed toggle) as limit

Example fix

# before
collection.delete(where={"topic": "news"}, limit="100")  # TypeError

# after
collection.delete(where={"topic": "news"}, limit=100)
Defensive patterns

Strategy: type-guard

Validate before calling

limit = int(limit) if isinstance(limit, (int, float)) and not isinstance(limit, bool) else None

Type guard

def is_valid_limit(v) -> bool:
    return isinstance(v, int) and not isinstance(v, bool) and v >= 0

Prevention

When it happens

Trigger: `collection.delete(where={...}, limit=10.0)`, `limit="10"`, `limit=True/False`, or limit coming from JSON/config that was not cast to int.

Common situations: Loading limit from a config file or API payload where numbers arrive as strings/floats; passing a boolean flag into the wrong keyword argument.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/c36e5f614b696cdf. Report an issue: GitHub.