Documentation
Guides

Query files with SQL

Run SQL over files in Amazon S3, Google Cloud Storage, and SFTP connections, and join the results with warehouse tables.

This page explains how to run SQL over the files in a storage connection without loading them first. A query can read files from Amazon S3, Google Cloud Storage, or SFTP, and join them with warehouse tables.

For each question, Bobsled AI downloads the selected files into a temporary, isolated sandbox. The sandbox runs the SQL and then stops. Bobsled AI keeps no copy of the files, so each new question reads the files again.

File queries work in chat, the API, and MCP. Background Agents can't query files.

Before you begin

  • Make sure that the Project has an Amazon S3, Google Cloud Storage, or SFTP connection. For more information, see Create and manage connections.
  • Make sure that you have read access to the Project. Anyone with read access can query every file on the Project's storage connections.

Ask Balto to query files

In a chat, name the connection, the folder or file, and the question, as in the following example:

Sum amount by vendor for the Parquet files in orders/2026-10/ on Vendor S3, and join vendor names from Snowflake.

Balto can list the folder and inspect the columns before it writes the SQL. To see what Balto read, open Query details on the result. The following table describes the fields:

Field
Meaning
FilesThe number of files in the query
Total sizeThe size of the files before decompression
FormatThe file format and the compression, if any
Files as ofThe time that Bobsled AI fixed the file list for this answer
First 10 of N or File namesThe names of up to 10 of the files

Query details for an example file query, with row counts, coverage, and the file count, total size, format, file list time, and first file names for an orders source.

Select files

A source selects one file or a pattern inside one folder. The following table shows the selection forms:

Selection
Use
{ "file": "orders/2026-10/day-01.parquet" }One file. Copy object from the file listing.
{ "folder": "orders/2026-10/", "glob": "*.parquet" }Files in a folder that match the pattern
{ "folder": "", "glob": "*.csv" }Files in the connection's saved folder or prefix

A selection follows these rules:

  • In a pattern, * matches inside one folder level, ** matches across folders, and ? matches one character.
  • All the files in one source must have the same format and compression.
  • A selection can contain up to 4,096 bytes.

Each source becomes a table with the name that you give the source. Each row also has a _source_file column that holds the name of its file. Bobsled AI rejects a file that has its own _source_file column.

Supported formats

Bobsled AI reads the format and the compression from the file name. For a compressed file, add .gz, .gzip, .zst, or .zstd after the format extension.

The following table lists the supported formats:

Format
File names
Compression
CSV.csvNone, gzip, or zstd
TSV.tsvNone, gzip, or zstd
JSON.jsonNone, gzip, or zstd
JSON Lines.jsonl, .ndjsonNone, gzip, or zstd
Parquet.parquetInternal compression only
Excel.xlsxInternal compression only

Check columns before a query

Balto uses describe_connection_files to read the columns of a selection. The tool reports the following:

  • The column names and types, from up to the first 10 files.
  • The row count, when the files give an exact count.
  • Up to 50 places where a file disagrees with the others, such as a missing column or a different type.

The API operation is POST /api/v1/projects/:projectId/agent-connections/:connectionId/files/describe. The body is { "select": <selection> }.

Use the API or MCP

Send a cross-source request to POST /api/v1/projects/:projectId/run-query, or call the MCP tool data_query with action: "run_query". Both accept the same request.

The following request joins Parquet files from an S3 connection with a Snowflake table:

json
{ "kind": "cross-source", "joinSql": "SELECT v.vendor_name, SUM(o.amount) FROM orders o JOIN vendors v USING (vendor_id) GROUP BY 1", "sources": [ { "kind": "file", "name": "orders", "connectionId": "S3_CONNECTION_ID", "select": { "folder": "orders/2026-10/", "glob": "*.parquet" } }, { "kind": "warehouse", "name": "vendors", "connectionId": "SNOWFLAKE_CONNECTION_ID", "sql": "SELECT vendor_id, vendor_name FROM DIM_VENDOR" } ] }

Replace the following:

  • S3_CONNECTION_ID: the UUID of the S3 connection.
  • SNOWFLAKE_CONNECTION_ID: the UUID of the Snowflake connection.

A request follows these rules:

  • Every source must have kind, with the value "file" or "warehouse". A request without kind on a source fails validation. Add kind to existing warehouse sources.
  • A query with one source is allowed only when that source is a file.
  • An uploaded file and a storage file can't be in the same query.

How Bobsled AI detects changed files

Bobsled AI fixes the file list before it downloads anything. How it detects a change depends on the provider:

  • S3 and Google Cloud Storage: Bobsled AI fixes the object version of each file. A changed object fails the query.
  • SFTP: SFTP has no object version, so Bobsled AI compares each file's size and modified time. This check is best effort. If a file is overwritten with the same size and the same modified time, Bobsled AI reads the new content without an error.

If the SFTP check affects your results, ask the file owner to use new names for new data.

Export the full result

Export full result (CSV) runs the query again against the files that the answer used. Bobsled AI lists the files again and ignores files that are newer than the answer. If a file that the answer used has changed or disappeared, the export fails.

When the files changed, the card shows Full export failed and this text: The files changed since this answer. Ask again. Bobsled AI turns off Regenerate. To read the current files, ask Balto the question again.

If Bobsled AI can't reach the connection, the card doesn't show that text. Regenerate can succeed after the connection recovers.

For the export lifecycle and download rules, see Export results.

Limits

The following table lists the limits for file queries:

Limit
Value
Sources in one query10
Files in one source10,000
Total size of one query on S3 or Google Cloud Storage5 GiB
Total size of one query on SFTP2 GiB
Size of decompressed data16 GiB
Time for one query280 seconds
Columns in a file1,000
Characters in a column name255
Running downloads on one SFTP connection2

Bobsled AI checks the listed file sizes before it downloads anything. If the files can't finish downloading in the query time, the query stops with connection_file_rate_limited. Select fewer or smaller files.

SFTP downloads

An SFTP connection allows 2 file query downloads at the same time. Each download uses 1 SSH connection with up to 16 parallel reads. A third download fails with connection_busy. Try the query again when a download finishes.

Bobsled AI holds a lease for each running download. The lease ends when the download finishes or when the query time ends.

The lease covers file query downloads only. It doesn't count or limit these activities:

  • Browsing a connection with Browse assets.
  • Balto's list_connection_files and read_connection_file tools.
  • Connection tests.
  • Pipeline runs.
  • Another Bobsled AI connection to the same server.

If a server accepts few connections, plan for these activities together with file queries.

Errors

The following table lists the error codes and the action for each. Bobsled AI returns these codes without file contents or provider messages.

Code
Action
connection_busyWait for a running SFTP download to finish, and then try again.
connection_file_changedThe file changed during the query. List the files, and then try again.
connection_file_column_limitSelect files with up to 1,000 columns.
connection_file_column_name_too_longRename columns to 255 characters or fewer.
connection_file_credentials_unavailableCheck the connection in Connections.
connection_file_decompressed_limitSelect fewer files.
connection_file_download_failedTry again. If it fails again, check the connection.
connection_file_download_timeoutSelect fewer or smaller files.
connection_file_invalidBobsled AI couldn't parse a file. Check that the file matches its name.
connection_file_listing_truncatedThe folder has too many entries. Choose a narrower folder.
connection_file_mixed_formatSelect files with one format and one compression.
connection_file_not_foundList the files, and select a file that exists.
connection_file_query_failedCheck the SQL and the columns.
connection_file_rate_limitedSelect fewer or smaller files.
connection_file_reserved_columnRemove the _source_file column from the file.
connection_file_selection_emptyChange the folder or the pattern.
connection_file_size_limitSelect less than 5 GiB, or 2 GiB on SFTP.
connection_file_source_not_allowedUse a storage connection in this Project. Background Agents can't query files.
connection_file_unsupported_formatUse a supported format.

What's next

On this page