Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Shared Params Comparison Filter

From Leeroopedia
Knowledge Sources
Domains API_Types, Python
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for specifying a comparison filter in vector store search and other filtering contexts, provided by the openai-python SDK.

Description

ComparisonFilter is a TypedDict that defines a filter for comparing a specified attribute key to a given value using a comparison operator. All three fields are required: key (the attribute to compare), type (the comparison operator such as eq, ne, gt, gte, lt, lte), and value (the comparison target supporting string, number, boolean, or sequence types). This is the shared_params variant used in request/input contexts.

Usage

Import this type when you need to build filters for vector store searches, file attribute filtering, or any API endpoint that accepts comparison-based filters.

Code Reference

Source Location

Signature

class ComparisonFilter(TypedDict, total=False):
    """A filter used to compare a specified attribute key to a given value
    using a defined comparison operation."""

    key: Required[str]
    type: Required[Literal["eq", "ne", "gt", "gte", "lt", "lte"]]
    value: Required[Union[str, float, bool, SequenceNotStr[Union[str, float]]]]

Import

from openai.types.shared_params import ComparisonFilter

I/O Contract

Fields

Name Type Required Description
key str Yes The key to compare against the value.
type Literal["eq", "ne", "gt", "gte", "lt", "lte"] Yes The comparison operator (eq=equals, ne=not equal, gt=greater than, gte=greater or equal, lt=less than, lte=less or equal).
value Union[str, float, bool, SequenceNotStr[Union[str, float]]] Yes The value to compare against; supports string, number, boolean, or sequence of strings/numbers.

Usage Examples

from openai.types.shared_params import ComparisonFilter

# Filter for documents with category equal to "engineering"
filter_eq: ComparisonFilter = {
    "key": "category",
    "type": "eq",
    "value": "engineering",
}

# Filter for documents with score greater than 0.8
filter_gt: ComparisonFilter = {
    "key": "score",
    "type": "gt",
    "value": 0.8,
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment