:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(batch-exports): surface hogql file download model in mcp (#88285)
Rossa99097a21c53
diff --git a/products/batch_exports/backend/api/file_download.py b/products/batch_exports/backend/api/file_download.pyindex a9fa76d0fb47..2dd3a5a5867d 100644--- a/products/batch_exports/backend/api/file_download.py+++ b/products/batch_exports/backend/api/file_download.py@@ -101,9 +101,13 @@ class FileDownloadSessionsRequestSerializer(serializers.Serializer):HOGQL_QUERY_HELP_TEXT = (- "HogQL SELECT query whose results are exported. Placeholders are not currently supported, "- "and every column in the SELECT clause must be a field or have an alias. The query runs as of the"- "time the export starts; events ingested moments before may not be included yet."+ "HogQL SELECT query whose results are exported. This model is in closed beta and is enabled "+ "per team; when it is not enabled, the request fails with a permission error that names HogQL "+ "batch exports. Contact PostHog support to request access. Placeholders are not currently "+ "supported, and every column in the SELECT clause must be a field or have an alias. It is "+ "recommended to limit the query with a WHERE clause, for example bounding timestamp on the "+ "events table, both to avoid exporting more rows than expected and because user queries run "+ "under stricter resource limits than the other models.")diff --git a/products/batch_exports/frontend/generated/api.schemas.ts b/products/batch_exports/frontend/generated/api.schemas.tsindex 00126977691c..27297ec9312e 100644--- a/products/batch_exports/frontend/generated/api.schemas.ts+++ b/products/batch_exports/frontend/generated/api.schemas.ts@@ -1658,7 +1658,7 @@ export const FileDownloadHogQLRequestApiModel = {export interface FileDownloadHogQLRequestApi {file: FileDownloadDestinationFileConfigApimodel: FileDownloadHogQLRequestApiModel- /** HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet. */+ /** HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models. */hogql_query: string}@@ -1754,7 +1754,7 @@ export interface FileDownloadBatchExportOnDemandApi {model: FileDownloadBatchExportOnDemandModelEnumApiinclude?: string[]exclude?: string[]- /** HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet. */+ /** HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models. */hogql_query?: string/** Start of the data interval to export */data_interval_start?: stringdiff --git a/products/batch_exports/frontend/generated/api.zod.ts b/products/batch_exports/frontend/generated/api.zod.tsindex 1f810148eeaa..e0dc99526f5b 100644--- a/products/batch_exports/frontend/generated/api.zod.ts+++ b/products/batch_exports/frontend/generated/api.zod.ts@@ -2884,7 +2884,7 @@ export const FileDownloadBatchExportsCreateBody = /* @__PURE__ */ zod.union([hogql_query: zod.string().describe(- 'HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet.'+ 'HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models.'),}).describe('Typed configuration for the hogql model.'),@@ -2934,7 +2934,7 @@ export const FileDownloadBatchExportsCancelCreateBody = /* @__PURE__ */ zod.string().optional().describe(- 'HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet.'+ 'HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models.'),data_interval_start: zod.iso.datetime({ offset: true })diff --git a/products/batch_exports/mcp/tools.yaml b/products/batch_exports/mcp/tools.yamlindex b452597e785a..7a410db3fc32 100644--- a/products/batch_exports/mcp/tools.yaml+++ b/products/batch_exports/mcp/tools.yaml@@ -201,11 +201,16 @@ tools:idempotent: falsetitle: Start file download exportdescription: >- Start an on-demand batch export that prepares downloadable files for events, persons, or sessions. Provide- data_interval_start and data_interval_end as ISO 8601 datetimes; the interval must be at most one week. For- events, include and exclude filter event names. Use file-download-batch-exports-retrieve with the returned- id to poll until status is Completed, then follow the downloading-batch-export-files skill to download the- files through the existing REST download endpoint.+ Start an on-demand batch export that prepares downloadable files for events, persons, sessions, or the+ results of a HogQL query. For events, persons and sessions, provide data_interval_start and+ data_interval_end as ISO 8601 datetimes; the interval must be at most one week, and for events, include and+ exclude filter event names. The hogql model is in closed beta and is enabled per team: it takes a+ hogql_query instead of a data interval, and returns a permission error naming HogQL batch exports when the+ team does not have it enabled, in which case tell the user they can contact PostHog support to request+ access. Limit hogql_query with a WHERE clause to export only the data the user asked for, because user+ queries run under stricter resource limits than the other models. Use file-download-batch-exports-retrieve+ with the returned id to poll until status is Completed, then follow the downloading-batch-export-files skill+ to download the files through the existing REST download endpoint.file-download-batch-exports-download-retrieve:operation: file_download_batch_exports_download_retrieveenabled: falsediff --git a/products/batch_exports/skills/downloading-batch-export-files/SKILL.md b/products/batch_exports/skills/downloading-batch-export-files/SKILL.mdindex 6b3c7bd09fe6..161e4c98b96d 100644--- a/products/batch_exports/skills/downloading-batch-export-files/SKILL.md+++ b/products/batch_exports/skills/downloading-batch-export-files/SKILL.md@@ -1,10 +1,10 @@---name: downloading-batch-export-filesdescription: >- Export PostHog events, persons, or sessions on demand and download the resulting files. Use when the user asks to- download/export raw PostHog data, create a one-off file export, fetch a Parquet or JSONLines export, or use the- file_download_batch_exports API. Covers starting the export with MCP, polling completion, and downloading via the- existing REST redirect endpoint.+ Export PostHog events, persons, sessions, or the results of a HogQL query on demand and download the resulting+ files. Use when the user asks to download/export raw PostHog data, export HogQL query results, create a one-off+ file export, fetch a Parquet or JSONLines export, or use the file_download_batch_exports API.+ Covers starting the export with MCP, polling completion, and downloading via the existing REST redirect endpoint.---# Downloading batch export files@@ -28,8 +28,9 @@ That endpoint is a redirecting file download endpoint, so raw HTTP/download handAsk a short clarifying question if the user did not specify the required inputs:-- `model`: one of `events`, `persons`, or `sessions`-- `data_interval_start` and `data_interval_end`: ISO 8601 datetimes; the range must be at most one week+- `model`: one of `events`, `persons`, `sessions`, or `hogql`+- `data_interval_start` and `data_interval_end`: ISO 8601 datetimes; the range must be at most one week.+ Required for `events`, `persons`, and `sessions`, and not supported for `hogql`- `file.format`: `Parquet` or `JSONLines`; prefer `Parquet` for compact analytics exports and `JSONLines` for line-oriented text processing- `file.compression`: optional, one of `zstd`, `gzip`, `brotli`, `lz4`, or `snappy`. If `JSONLines` was chosen as format, only `gzip` and `brotli` are supported.- `file.max_size_mb`: optional maximum part size in MB; set this when the user wants multiple smaller files instead of a single (potentially large) file.@@ -37,6 +38,13 @@ Ask a short clarifying question if the user did not specify the required inputs:For `events`, `include` and `exclude` are optional event-name filters.Use them only when the user asks for specific events or wants to omit specific events.+For `hogql`, pass the query as `hogql_query` and leave out `data_interval_start`, `data_interval_end`, `include`, and `exclude`.+The query runs as of the time the export starts, so there is no interval to choose.+You may prompt the user to export a slice of data by including a WHERE clause in the HogQL query, for example limiting results from the `events` table by bounding `timestamp`.+Always prefer limiting the data exported to the minimum necessary to solve the user's request.+Every column in the SELECT clause must be a field or have an alias, and placeholders are not supported.+This model is in closed beta and is enabled per team.+### 2. Start the exportCall `posthog:file-download-batch-exports-create` with the selected shape.@@ -57,6 +65,18 @@ Example request:}```+Example request for the `hogql` model:++```json+{+ "model": "hogql",+ "file": {+ "format": "Parquet"+ },+ "hogql_query": "SELECT event, timestamp, properties.$current_url AS url FROM events WHERE timestamp > now() - INTERVAL 1 HOUR"+}+```+### 3. Poll until completionCall `posthog:file-download-batch-exports-retrieve` with the returned `id`.@@ -117,9 +137,11 @@ posthog-events-<run_id>-<part>.jsonl.gzposthog-persons-<run_id>-<part>.parquet```-## Watch-outs+## Important notes- The maximum export interval is one week. Split longer user requests into separate export runs or ask which week to export.+- The `hogql` model is in closed beta and is enabled per team. A permission error that says HogQL batch exports are not enabled means the team does not have the beta. Report that instead of retrying with a different query, and tell the user they can contact PostHog support to request access.+- The `hogql` model runs under stricter resource limits than the other models, because user queries are less predictable. If an export fails on memory, execution time, or bytes read, suggest narrowing the query with a WHERE clause instead of retrying it unchanged.- A run can briefly report `Running` after completion while file records are being created. Poll again instead of failing immediately.- Download URLs are temporary. If a URL expires, call the REST download endpoint again for a fresh redirect.- Do not send the signed URL to unrelated services unless the user explicitly asks; it grants temporary access to the exported file.diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 5b27265b6802..f39d9f7cd85c 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -5130,7 +5130,7 @@}},"file-download-batch-exports-create": {- "description": "Start an on-demand batch export that prepares downloadable files for events, persons, or sessions. Provide data_interval_start and data_interval_end as ISO 8601 datetimes; the interval must be at most one week. For events, include and exclude filter event names. Use file-download-batch-exports-retrieve with the returned id to poll until status is Completed, then follow the downloading-batch-export-files skill to download the files through the existing REST download endpoint.",+ "description": "Start an on-demand batch export that prepares downloadable files for events, persons, sessions, or the results of a HogQL query. For events, persons and sessions, provide data_interval_start and data_interval_end as ISO 8601 datetimes; the interval must be at most one week, and for events, include and exclude filter event names. The hogql model is in closed beta and is enabled per team: it takes a hogql_query instead of a data interval, and returns a permission error naming HogQL batch exports when the team does not have it enabled, in which case tell the user they can contact PostHog support to request access. Limit hogql_query with a WHERE clause to export only the data the user asked for, because user queries run under stricter resource limits than the other models. Use file-download-batch-exports-retrieve with the returned id to poll until status is Completed, then follow the downloading-batch-export-files skill to download the files through the existing REST download endpoint.","category": "Data pipelines","feature": "batch_exports","summary": "Start file download export",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 318f96786df6..8a6ca14dd913 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -5285,7 +5285,7 @@}},"file-download-batch-exports-create": {- "description": "Start an on-demand batch export that prepares downloadable files for events, persons, or sessions. Provide data_interval_start and data_interval_end as ISO 8601 datetimes; the interval must be at most one week. For events, include and exclude filter event names. Use file-download-batch-exports-retrieve with the returned id to poll until status is Completed, then follow the downloading-batch-export-files skill to download the files through the existing REST download endpoint.",+ "description": "Start an on-demand batch export that prepares downloadable files for events, persons, sessions, or the results of a HogQL query. For events, persons and sessions, provide data_interval_start and data_interval_end as ISO 8601 datetimes; the interval must be at most one week, and for events, include and exclude filter event names. The hogql model is in closed beta and is enabled per team: it takes a hogql_query instead of a data interval, and returns a permission error naming HogQL batch exports when the team does not have it enabled, in which case tell the user they can contact PostHog support to request access. Limit hogql_query with a WHERE clause to export only the data the user asked for, because user queries run under stricter resource limits than the other models. Use file-download-batch-exports-retrieve with the returned id to poll until status is Completed, then follow the downloading-batch-export-files skill to download the files through the existing REST download endpoint.","category": "Data pipelines","feature": "batch_exports","summary": "Start file download export",diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 9c78dffaa212..a40fa197735d 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -19324,7 +19324,7 @@ export namespace Schemas {export interface FileDownloadHogQLRequest {file: FileDownloadDestinationFileConfig;model: FileDownloadHogQLRequestModel;- /** HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet. */+ /** HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models. */hogql_query: string;}@@ -38805,7 +38805,7 @@ export namespace Schemas {model: FileDownloadBatchExportOnDemandModelEnum;include?: string[];exclude?: string[];- /** HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet. */+ /** HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models. */hogql_query?: string;/** Start of the data interval to export */data_interval_start?: string;diff --git a/services/mcp/src/generated/batch_exports/api.ts b/services/mcp/src/generated/batch_exports/api.tsindex 375cb5975b49..33a495b1526b 100644--- a/services/mcp/src/generated/batch_exports/api.ts+++ b/services/mcp/src/generated/batch_exports/api.ts@@ -897,7 +897,7 @@ export const FileDownloadBatchExportsCreateBody = /* @__PURE__ */ zod.union([hogql_query: zod.string().describe(- 'HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet.'+ 'HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models.'),}).describe('Typed configuration for the hogql model.'),@@ -972,7 +972,7 @@ export const FileDownloadBatchExportsCancelCreateBody = /* @__PURE__ */ zod.string().optional().describe(- 'HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet.'+ 'HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models.'),data_interval_start: zod.iso.datetime({ offset: true })diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-cancel-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-cancel-create.jsonindex e6ab9340d914..dc5a527b3ea7 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-cancel-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-cancel-create.json@@ -57,7 +57,7 @@"type": "object"},"hogql_query": {- "description": "HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet.",+ "description": "HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models.","type": "string"},"id": {diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.jsonindex 90b8fea239d4..d5d30ca51789 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/file-download-batch-exports-create.json@@ -228,7 +228,7 @@"type": "object"},"hogql_query": {- "description": "HogQL SELECT query whose results are exported. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. The query runs as of thetime the export starts; events ingested moments before may not be included yet.",+ "description": "HogQL SELECT query whose results are exported. This model is in closed beta and is enabled per team; when it is not enabled, the request fails with a permission error that names HogQL batch exports. Contact PostHog support to request access. Placeholders are not currently supported, and every column in the SELECT clause must be a field or have an alias. It is recommended to limit the query with a WHERE clause, for example bounding timestamp on the events table, both to avoid exporting more rows than expected and because user queries run under stricter resource limits than the other models.","type": "string"},"model": {