Overview
LangSmith provides a powerful query language for filtering and searching traces. This syntax is used throughout the platform for filtering traces in the UI, exporting data, and programmatically querying your trace data.Basic Syntax
The query language supports filtering on various trace attributes using a simple key-value format:Examples
Filter Arguments
Run Type Filters
Filter traces by the type of run:Status Filters
Filter by run status:Name Filters
Filter by run name:Time Filters
Filter by timestamp ranges:Metadata Filters
Filter by custom metadata:Tag Filters
Filter by tags:Filter Query Language
For more complex queries, you can use the advanced filter query language with logical operators and nested conditions.Logical Operators
AND
: All conditions must be trueOR
: At least one condition must be trueNOT
: Negate a condition
Examples
Nested Conditions
Use parentheses for complex logical groupings:Comparison Operators
For numeric and date fields, you can use comparison operators:=
: Equal to!=
: Not equal to>
: Greater than>=
: Greater than or equal to<
: Less than<=
: Less than or equal to
String Matching
For string fields, you can use pattern matching:contains
: Contains substringstarts_with
: Starts with prefixends_with
: Ends with suffixregex
: Regular expression match
Advanced Examples
Complex Filtering
Performance Considerations
- Use specific filters to reduce query time
- Avoid overly broad date ranges
- Consider using tags for frequently filtered attributes
- Use metadata sparingly for high-cardinality data
API Usage
When using the LangSmith API, you can pass these filters as query parameters:Best Practices
- Use specific filters: Narrow down your search to improve performance
- Leverage tags: Use tags for commonly filtered attributes
- Optimize metadata: Keep metadata keys consistent and meaningful
- Test queries: Verify your filter syntax before using in production
- Monitor performance: Complex queries may take longer to execute
Troubleshooting
Common Issues
- No results: Check for typos in filter values
- Slow queries: Simplify complex filters or add time constraints
- Syntax errors: Verify operator usage and parentheses matching
Debugging Tips
- Start with simple filters and build complexity gradually
- Use the UI to test filters before implementing in code
- Check the API documentation for field names and values