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 Compound Filter

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

Overview

Concrete tool for combining multiple filters using logical AND/OR operations provided by the openai-python SDK.

Description

CompoundFilter is a Pydantic BaseModel that combines multiple filters using logical and or or operations. It contains a filters list of Filter items (a TypeAlias for Union[ComparisonFilter, object]), where each item can be a ComparisonFilter or another CompoundFilter for nested logic. The type field specifies whether the combination is "and" or "or". This enables construction of arbitrarily complex filter expressions for vector store queries and other filterable API endpoints.

Usage

Import CompoundFilter when you need to combine multiple ComparisonFilter conditions with logical operators for API queries.

Code Reference

Source Location

Signature

Filter: TypeAlias = Union[ComparisonFilter, object]

class CompoundFilter(BaseModel):
    filters: List[Filter]
    type: Literal["and", "or"]

Import

from openai.types.shared import CompoundFilter

I/O Contract

Fields

Name Type Required Description
filters List[Filter] Yes Array of filters to combine. Items can be ComparisonFilter or CompoundFilter for nested logic.
type Literal["and", "or"] Yes Type of logical operation: "and" (all must match) or "or" (any must match).

Usage Examples

from openai.types.shared import CompoundFilter, ComparisonFilter

# Combine filters with AND logic
combined_filter = CompoundFilter(
    type="and",
    filters=[
        ComparisonFilter(key="category", type="eq", value="science"),
        ComparisonFilter(key="year", type="gte", value=2024),
    ],
)

# Combine filters with OR logic
or_filter = CompoundFilter(
    type="or",
    filters=[
        ComparisonFilter(key="status", type="eq", value="published"),
        ComparisonFilter(key="status", type="eq", value="reviewed"),
    ],
)

Related Pages

Page Connections

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