> ## Documentation Index
> Fetch the complete documentation index at: https://docs.braintrust.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Log filtering with large user ID sets

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Braintrust-hosted
> *
> * Use case - BTQL log filtering with more than 128 user IDs or other metadata values

## Summary

**Issue:** Filtering logs with chained `OR` operations like `metadata.user_id MATCH 'id1' OR metadata.user_id MATCH 'id2'` fails when exceeding 128 conditions due to a backend JSON nesting recursion limit.

**Cause:** Chained `OR` queries are nested in JSON on the backend and hit the 128 query recursion limit.

**Resolution:** Use the `IN` operator instead of chained `OR` operations to filter by large sets of user IDs.

## Resolution Steps

### Use the IN operator for large ID sets

#### Step 1: Replace chained OR queries with IN operator

Use the `IN` operator for filtering metadata fields.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
metadata.user_id in ('50157c3d-edd9-4287-85ee-48c119967099', 'a3fe059a-e4f4-4e9f-b3e3-0da04ed1f075', '913b6ae1-72aa-4113-964e-e41364933a43')
```

#### Step 2: Verify query performance

The `IN` operator supports 300+ IDs and avoids the recursion limit entirely.

### Alternative: Use the API for programmatic filtering

#### Step 1: Query logs via Braintrust API

Use the Braintrust API to fetch and filter logs programmatically if the `IN` operator doesn't meet your requirements.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.