Skip to content

Fix: --sessions SQL query uses FILTER(WHERE) unsupported by BTQL #169

@stephenfeather

Description

@stephenfeather

Bug

The --sessions command in scripts/braintrust_analyze.py fails with a SQL parse error:

SQL Error: 400 - Expected: end of statement, found: ( at Line: 7, Column: 29

Cause

The list_sessions() function (line 332) uses PostgreSQL's COUNT(*) FILTER (WHERE ...) syntax, which BTQL does not support.

COUNT(*) FILTER (WHERE span_attributes['type'] = 'tool') as tool_count

Fix

Replace with standard SQL SUM(CASE WHEN ... END):

SUM(CASE WHEN span_attributes['type'] = 'tool' THEN 1 ELSE 0 END) as tool_count

Tested and confirmed working against the Braintrust API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions