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
- Pass a plain int: `collection.delete(where=..., limit=10)`
- Coerce external values first: `limit = int(limit)` (after range-checking)
- 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
- Coerce config/env values to int at load time, not at the call site
- Remember bool is an int subclass — never pass flags as limit
- Wrap delete calls in a helper that type-checks limit once
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
- limit can only be specified when a where or where_document c
- limit must be a non-negative integer
- limit can only be specified when a where or where_document c
- Limit offset must be a non-negative integer
- Limit must be a positive integer when provided
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/c36e5f614b696cdf.
Report an issue: GitHub.