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:

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"].

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.