Skip to main content
The LangSmith SDK and REST API let you filter, query, and export runs programmatically using a set of filter arguments and a structured filter query language. This page documents the filter arguments and query language, with examples for common queries. For runnable end-to-end examples that combine these filters with the SDK, refer to Query traces using the SDK.

Filter arguments

Performance tip: Passing the select parameter and excluding inputs and outputs from the list can significantly improve query performance and reduce response sizes, especially for large runs.

Filter query language

LangSmith supports filtering capabilities with a filter query language to permit complex filtering operations when fetching runs. This is especially useful when querying traces programmatically via the SDK or API. For example, in evaluation pipelines, monitoring scripts, or agentic workflows that inspect prior traces.

Comparators

The filtering grammar is based on comparator functions applied to fields of the run object:

Wildcard pattern matching

like and notlike match a field value against a pattern. How the pattern applies depends on the field:
  • name, metadata_key, and metadata_value: % matches any sequence of characters, including none. Matching is case-sensitive. Without %, like matches only the exact value, the same as eq.
  • inputs, outputs, and error: Matching is case-insensitive and always matches a substring, so % is optional. LangSmith can match each word of the pattern separately rather than as a phrase, so do not rely on like to match an exact phrase in these fields.
For example:
  • like(metadata_value, "%prod%") matches any value that contains prod, such as production or eu-prod-1.
  • notlike(metadata_value, "%staging%") matches any value that does not contain staging.
In the UI filter builder, the contains and does not contain operators produce like and notlike filters. To translate a search bar query, refer to the UI-to-API operator map.

Logical operators

Use and and or to combine multiple comparators:

Filterable fields

Value formatting

  • Strings: wrap in double or single quotes, eq(name, "MyChain") or eq(name, 'MyChain').
  • Timestamps: ISO 8601 format, "2024-06-01T00:00:00Z".
  • Durations: seconds, as either a number or a string with the s suffix, "5s", "1.5s", "90s", or 1.5. Other unit suffixes (m, h) are not supported.
  • Lists: JSON array syntax, ["session_id", "thread_id"].

UI-to-API operator map

The search bar in the LangSmith UI uses its own syntax, documented in Filter traces. The following table maps each search bar operator to the comparator that does the same job in this language:

Alert filters

Alert rules accept the same filter query language in their filter and denominator_filter fields:
  • filter: Selects the runs that count toward the alert.
  • denominator_filter: Selects the baseline population for a percentage-based alert. When it is empty, every run counts toward the baseline.
Alert filters accept only and. Combining conditions with or is not supported. Example alert filter that matches runs whose env metadata value does not contain staging:

Quick reference examples

The following examples show the filter string only. Pass the string as the filter, trace_filter, or tree_filter argument in client.list_runs() or the /runs/query API endpoint.
For complete SDK examples with Python, TypeScript, and Java code, refer to Query traces using the SDK.

Filter by run name

Filter by error status

Filter by latency

Filter by time range

Filter by tags

Filter by metadata key or value

Filter by thread ID

Filter by feedback score

Full-text search across all string fields

Combining conditions

Using trace_filter and tree_filter

filter applies to the returned run. trace_filter applies to the root run of the trace. tree_filter applies to any run anywhere in the trace tree.
tree_filter applies the same query syntax to runs anywhere in the trace tree. For predicates over arbitrary nested child-run fields, such as returned inputs, outputs, or extra payload paths, first narrow candidates with server-side filters, then hydrate root traces with child runs and traverse them locally. See Query trace trees with child-run predicates.