chroma-core/chroma · error · TypeError

$regex requires a string pattern, got

Error message

$regex requires a string pattern, got {type(value).__name__}

What it means

Raised by Where.from_dict when the '$regex' operator's value is not a string — e.g. a compiled pattern object or a non-string was passed. The regex filter requires its pattern as a plain string.

Solutions

  1. Pass a regex pattern string: {"field": {"$regex": "^pattern"}}
  2. Validate the pattern is a valid regex before submitting
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at chromadb/execution/expression/operator.py:201 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at chromadb/execution/expression/operator.py:201

                        raise TypeError(
                            f"$nin requires a list, got {type(value).__name__}"
                        )
                    return Key(field).not_in(value)
                elif op == "$contains":
                    if not isinstance(value, (str, int, float, bool)):
                        raise TypeError(
                            f"$contains requires a str, int, float, or bool, got {type(value).__name__}"
                        )
                    return Key(field).contains(value)
                elif op == "$not_contains":
                    if not isinstance(value, (str, int, float, bool)):
                        raise TypeError(
                            f"$not_contains requires a str, int, float, or bool, got {type(value).__name__}"
                        )
                    return Key(field).not_contains(value)
                elif op == "$regex":
                    if not isinstance(value, str):
                        raise TypeError(
                            f"$regex requires a string pattern, got {type(value).__name__}"
                        )
                    return Key(field).regex(value)
                elif op == "$not_regex":
                    if not isinstance(value, str):
                        raise TypeError(
                            f"$not_regex requires a string pattern, got {type(value).__name__}"
                        )
                    return Key(field).not_regex(value)
                else:
                    raise ValueError(f"Unknown operator: {op}")
            else:
                # Direct value is shorthand for equality
                return Key(field) == condition

    def __and__(self, other: "Where") -> "And":
        """Overload & operator for AND"""
        # If self is already an And, extend it

View on GitHub (pinned to aecdd12c8a)