Skip to content
Menu

SQL execution gate

View .md

Beacon runs SQL on your data sources for several features: the MCP tools query, ask and dry_run, saved-query tools, query previews, subscriptions, AI actor checks, data contract rules, column value samples and migration reads. Every one of them sends its statement through one component, the SQL execution gate (ISqlExecutionGate), before anything connects to the data source.

The gate exists because a text-to-SQL system must never trust the text it is given. It protects against:

  • writes and other side effects hidden in a SELECT (stacked statements, SELECT ... INTO, data-changing CTEs, locking hints)
  • reads that leave the data source’s boundary (another database, a linked server, a file, a URL, a model)
  • reads of the engine’s own catalog, statistics and query history, which can expose values and other people’s queries
  • result sets large enough to exhaust memory or a warehouse budget

Read this page when you need to know exactly what Beacon refuses and why, when you tune the limits, or when a user reports a refused query and you need to explain the message. The short overview is in Security overview, section 6. The gate is defence in depth: it is the main control, and a read-only database login (see Database-level read-only) is the second.

The gate is pure and synchronous. It does no I/O, so it can judge every candidate statement, including every repair attempt of the ask tool, for the cost of a parse. It returns a report with the verdict of each stage, the SQL to run (FinalSql) and, when it blocks, the reason. What runs on the data source is always the gate’s own FinalSql, never SQL changed after the gate.

The stages run in this order. A failure in an early stage skips the later ones (their verdict is not_evaluated).

flowchart TD
  A[SQL text] --> B[1. Length cap]
  B --> C[2. Disallowed characters]
  C --> D[3. Regex guardrail]
  D --> E[4. AST read-only validator]
  E --> F[5. Cross-database rule]
  F --> G[6. System catalog rule]
  G --> H[7. Row-level security]
  H --> I[8. Host policy]
  I --> J[9. Schema check]
  J --> K[10. Semantic lint]
  K --> L[11. Row cap]
  L --> M[FinalSql runs through the read-only path]
#StageVerdict code on failureBlocks always?
1Length capsql_too_longYes
2Disallowed charactersdisallowed_characterYes
3Regex guardrailguardrail (or empty for blank SQL)Only while read-only enforcement is on, except blank SQL and a custom PII pattern that cannot be evaluated, which always fail
4AST read-only validatorastOnly while read-only enforcement is on
5Cross-database rulecross_databaseYes, also with read-only off
6System catalog rulesystem_catalogYes, also with read-only off
7Row-level securityno_entitlement, row_security_unrewritableYes
8Host policyhost_policyYes
9Schema checkschemaOnly where the caller asks it to block (the MCP query tool does)
10Semantic lintnone (findings only)No, advisory
11Row capuncappable_bound, invalid_row_cap, too_deepYes

Other codes are not failures: not_requested (the caller did not ask for the stage), not_evaluated (an earlier stage blocked), disabled (switched off by settings), already_limited, own_bound_capped, not_applicable, textual_fallback, empty_catalog and parse_failed.

Stages 5 to 8 are authorization, not advice: they block whatever the read-only and schema settings say. Only the statement that joins step results on Beacon’s own in-memory SQLite database skips stages 5 and 6, because it reaches no other database.

  • Features of Beacon itself (previews, subscriptions, AI actor checks, data contract rules, samples, migration reads) go through GatedSqlRunner. It always runs the gate with read-only enforcement on, a mandatory row cap and a statement timeout, and refuses a statement that names a database other than the one the connection is configured for.
  • MCP tools call the gate with the effective MCP settings of the project (the strictest of the projects that link the data source). The deployment lock Beacon:Mcp:ForceReadOnly (default on) makes the gate enforce read-only whatever those settings say. If an Admin’s stored setting had read-only off, a refusal that only read-only enforcement causes says so: ... Read-only enforcement is on because the deployment lock Beacon:Mcp:ForceReadOnly pins it, whatever the stored MCP settings say.

The length cap runs first so no regex or parser ever sees an over-long input. The default is 100,000 characters (Beacon:Mcp:Ceilings:MaxSqlChars).

The character check refuses control characters other than tab, line feed and carriage return, and every Unicode noncharacter. The parser reads U+FFFF as the end of its input, so without this check every later stage would judge only the text before it. Both checks apply whatever the read-only setting, the in-memory join included.

InputVerdictMessage
100,001 characters with the default ceilingsql_too_longSQL is 100001 characters long; the limit is 100000.
SELECT 1 followed by a NUL bytedisallowed_characterThe SQL holds a control character or a Unicode noncharacter at position 9. Remove it: besides text, only tabs and line breaks are allowed.

The messages carry counts and positions only, never SQL text.

A cheap first filter on the SQL text with comments removed by the dialect’s own tokenizer (SqlCommentStripper). It refuses anything that does not begin with SELECT, WITH or EXPLAIN and anything containing a write keyword. It also runs PII detection on the SQL text (see PII detection).

StatementDialectVerdictWhy
DELETE FROM ordersPostgreSQLguardrailWrite operations are not allowed. Only SELECT queries are permitted.
SELECT 1; DROP TABLE ordersPostgreSQLguardrailSame message: the write keyword is found anywhere in the text
WITH x AS (INSERT INTO t VALUES(1) RETURNING id) SELECT * FROM xPostgreSQLguardrailA data-modifying CTE
EXPLAIN ANALYZE DELETE FROM ordersPostgreSQLguardrailEXPLAIN ANALYZE runs the wrapped write on PostgreSQL
COPY accounts TO PROGRAM 'nc host 9'PostgreSQLguardrailQuery must start with SELECT, WITH, or EXPLAIN.
(blank)anyemptyQuery cannot be empty

The statement is parsed in the data source’s own dialect (DataSourceSqlDialect.Of) and the syntax tree is walked. A dialect that is unknown or missing is refused: Beacon never judges SQL under a generic grammar. SQL that cannot be parsed is refused too (fail closed), with the parser’s message.

StatementDialectVerdictMessage
SELECT id, total FROM orders WHERE total > 100PostgreSQLpass
WITH recent AS (SELECT * FROM orders WHERE created_time > '2026-01-01') SELECT count(*) FROM recentPostgreSQLpass
EXPLAIN SELECT * FROM ordersPostgreSQLpass
SELECT 1; SELECT 2PostgreSQLastMultiple SQL statements are not allowed. Submit a single SELECT query.
SELECT * INTO evil FROM ordersPostgreSQLastSELECT ... INTO is not allowed because it creates a table. Submit a read-only SELECT.
SELECT id FROM orders FOR UPDATEPostgreSQLastRow-locking clauses (FOR UPDATE / FOR SHARE) are not allowed in read-only SQL.
SELECT nextval('orders_id_seq')PostgreSQLastThe function nextval is not allowed in read-only SQL: it reaches files, other servers or settings, or holds resources.
SELECT pg_read_file('/etc/passwd')PostgreSQLastSame message, naming pg_read_file
SELECT * FROM dblink('host=x', 'select 1')PostgreSQLastSame message, naming dblink
SELECT * FROM orders WITH (UPDLOCK)SQL ServerastLocking table hints (UPDLOCK, XLOCK, TABLOCK, TABLOCKX, HOLDLOCK, SERIALIZABLE) are not allowed in read-only SQL.
SELECT id FROM orders COMMITSQL ServerastCOMMIT cannot be an unquoted alias on SQL Server, where it can start a new statement. Quote it ([COMMIT]) or choose another alias.
SELECT * FROM srv.Sales.dbo.ordersSQL ServerastNames with four or more parts are not allowed: they reach a linked server. Use schema.table or database.schema.table.
SELECT * FROM [srv].[Sales].[dbo].[orders]Azure SynapseastSame four-part message
SELECT /*! 1 */ id FROM ordersMySQLastMySQL executable comments (/*! ... */) and optimizer hints (/*+ ... */) are not allowed.
SELECT id FROM orders --1MySQLastOn MySQL, -- starts a comment only when a space follows it. Add the space, or separate the minus signs.
SELECT * FROM read_files('/mnt/x')DatabricksastThe function read_files is not allowed in read-only SQL
SELECT * FROM json.`/mnt/landing/x` DatabricksastFile and storage path references (format.`path`) are not allowed. Query a catalog table instead.
SELECT * FROM EXTERNAL_QUERY('conn', 'SELECT 1')BigQueryastThe function EXTERNAL_QUERY is not allowed in read-only SQL
SELECT GET_PRESIGNED_URL(@stage, 'a.csv')SnowflakeastThe function GET_PRESIGNED_URL is not allowed in read-only SQL
SELECT 1 with no known dialectnoneastThe SQL dialect of this data source is not known, so the SQL cannot be verified as read-only.

The validator also refuses nested block comments on engines that do not nest them (an engine that ends a comment at its first */ would read a different statement from the one validated), a backslash before a quote where the engine does not use backslash escapes, U&'...' strings and misleading comment markers such as /*/. A PostgreSQL statement may nest comments, because PostgreSQL does: SELECT id FROM orders /* a /* b */ */ passes there.

SqlCrossDatabaseRule keeps a statement inside the database the connection is configured for. It refuses:

  • a name qualified with another database (catalog on Databricks, project on BigQuery)
  • every database qualifier when the configured database cannot be read or none is configured
  • functions and procedures that reach other servers, files, storage, models or secrets (OPENROWSET, OPENQUERY, dblink, lo_import, xp_cmdshell, read_files, EXTERNAL_QUERY, and others)
  • names with more parts than database.schema.table
  • statements that switch database, schema, role or user (USE, SET ROLE, EXECUTE AS)
  • statements that run SQL held in a string, variable or session (EXEC @sql, sp_executesql, EXECUTE IMMEDIATE, PREPARE/EXECUTE)
  • PostgreSQL COPY ... PROGRAM and server-file COPY
  • SQL it cannot parse

With read-only enforcement on (the default), the AST validator in stage 4 refuses most of the function cases first. The cross-database stage is the one that still holds when read-only enforcement is off, which is why it is listed separately.

StatementDialect and configured databaseVerdictMessage
SELECT * FROM sales.dbo.ordersSQL Server, salespass
SELECT * FROM dbo.ordersSQL Server, salespass
SELECT * FROM hr.dbo.salariesSQL Server, salescross_databaseThe SQL names an object in another database: only this data source's own database may qualify a name. Use schema.table names.
SELECT * FROM sales.dbo.ordersSQL Server, none readablecross_databaseThe SQL qualifies a name with a database, but this data source has no database configured, so only schema.table names are allowed.
SELECT * FROM mysql.userMySQL, nonecross_databaseThe SQL qualifies a name with a database, but this data source has no database configured, so only table names are allowed.
SELECT * FROM `sales-proj.sales.orders` BigQuery, sales-projpass
SELECT * FROM `other-proj.sales.orders` BigQuery, sales-projcross_databaseThe SQL names an object in another project: only this data source's own project may qualify a name. Use dataset.table names.
SELECT * FROM main.sales.ordersDatabricks, mainpass
SELECT * FROM other.sales.ordersDatabricks, maincross_databaseThe SQL names an object in another catalog: only this data source's own catalog may qualify a name. Use schema.table names.

With read-only enforcement off (an Admin turned it off and the deployment does not pin it), the same stage answers:

StatementDialectVerdictMessage
SELECT * FROM OPENQUERY(srv, 'SELECT 1')SQL Servercross_databaseOPENQUERY is not allowed: it reaches other servers, files, storage, models or secrets.
SELECT * FROM dblink('host=x', 'select 1')PostgreSQLcross_databasedblink is not allowed: it reaches other servers, files, storage, models or secrets.
SELECT * FROM srv.Sales.dbo.ordersSQL Servercross_databaseThe SQL uses a name with more parts than database.schema.table, which can reach another server or database.
USE hrSQL Servercross_databaseUSE is not allowed: it changes the database, schema, role or warehouse the SQL after it runs in. Write schema.table names instead.
EXEC sp_executesql N'SELECT 1'SQL Servercross_databasesp_executesql is not allowed: it runs SQL held in a string, a variable or the session, so the databases that SQL names cannot be checked.
EXECUTE AS LOGIN = 'sa'SQL Servercross_databaseEXECUTE AS is not allowed: it changes the role or user, and so the grants, the SQL runs with.
EXECUTE stmtMySQLcross_databaseEXECUTE is not allowed: it runs SQL held in a string, a variable or the session, so the databases that SQL names cannot be checked.
COPY accounts TO PROGRAM 'nc host 9'PostgreSQLcross_databaseCOPY to or from a program or a server file is not allowed: it reaches beyond the data source.

GatedSqlRunner judges a statement first as if the data source had no configured database, and reads the connection only when a statement names a database. A statement another stage refuses never causes the connection string to be decrypted.

SqlSystemCatalogRule refuses the engine’s catalog, statistics and query-history relations in every dialect, also as the table a DESCRIBE names. Those relations hold the most common values of a column (pg_stats), other sessions’ SQL (pg_stat_activity, sys.dm_exec_requests) and query history, none of which the PII masking sees. Beacon lists a source’s tables and columns from its own metadata, so no query needs them.

The rule covers system schemas and databases (pg_catalog, information_schema, SQL Server sys, MySQL mysql/performance_schema/sys, Snowflake SNOWFLAKE, BigQuery INFORMATION_SCHEMA), catalog-reserved names (pg_* in any schema, SQL Server compatibility views such as sysobjects, BigQuery __TABLES__, SQLite sqlite_* and pragma_*), system table functions by exact name (fn_dblog, RESULT_SCAN, Snowflake history functions), PostgreSQL pg_stat* and pg_get_* functions, and an unquoted PostgreSQL ONLY relation.

StatementDialectVerdictMessage
SELECT * FROM pg_statsPostgreSQLsystem_catalogpg_stats is a system catalog relation: SQL may read the data source's own tables only, not the engine's catalog, statistics or query history. Beacon lists the source's tables and columns from its own metadata.
SELECT query FROM pg_stat_activityPostgreSQLsystem_catalogSame message, naming pg_stat_activity
SELECT table_name FROM information_schema.columnsPostgreSQLsystem_catalogSame message, naming information_schema.columns
SELECT name FROM sys.tablesSQL Serversystem_catalogSame message, naming sys.tables
SELECT query FROM TABLE(INFORMATION_SCHEMA.QUERY_HISTORY())Snowflakesystem_catalogSame message, naming INFORMATION_SCHEMA.QUERY_HISTORY
SELECT * FROM TABLE(RESULT_SCAN(LAST_QUERY_ID(-1)))Snowflakesystem_catalogSame message, naming RESULT_SCAN
SELECT query FROM `region-us`.INFORMATION_SCHEMA.JOBSBigQuerysystem_catalogSame message
SELECT row_count FROM sales.__TABLES__BigQuerysystem_catalogSame message
SELECT * FROM sqlite_masterSQLitesystem_catalogSame message
SELECT id FROM orders AS pg_statsPostgreSQLpassAn alias is not a relation
SELECT id FROM dbo.system_eventsSQL ServerpassA user table whose name only starts with system

Every gate request carries a row-security context. Denied refuses the statement (no_entitlement: You have no access to the rows of this data source.). Filtered also refuses, because the gate cannot yet write a filter into a statement (row_security_unrewritable: Row-level security filters this data source, and the statement cannot be filtered, so it was not run.). A request with no context counts as Denied. The in-memory join and the save-time SQL checks, which reach no source’s rows, state NotApplicable.

Beacon:RowSecurity:Enabled is a deployment lock that is off by default. Turning it on fails startup, because row-level security is not available in this release:

Beacon:RowSecurity:Enabled cannot be turned on: row-level security is not available in this release.

Leave it unset. The check is in place so that no deployment believes its rows are filtered when they are not.

Stage 8 to 10: host policy, schema check and lint

Section titled “Stage 8 to 10: host policy, schema check and lint”
  • Host policy. A data source exposed by the host application with ExposeDbContext has an allow-list of tables and masked columns. A violation always blocks (host_policy). If the guard is not wired, the statement is refused: Host data source policy is unavailable; the query was not run.
  • Schema check. Compares tables and columns against the stored metadata. The MCP query tool blocks on it, so a column the model invented never reaches the warehouse. ask, dry_run and cross-source queries treat it as advice and repair. A source with no stored metadata yields empty_catalog, and query refuses it.
  • Semantic lint. Findings only, such as a join that multiplies rows. It never blocks.

Every statement that runs through GatedSqlRunner has a mandatory row cap, and the MCP tools pass one too. The gate writes the cap into the SQL, so the database never builds a bigger result. A bound the statement sets itself is kept when it is within the cap, and lowered to the cap when it is not.

StatementDialectCapFinalSqlVerdict
SELECT id, total FROM orders ORDER BY created_time DESCPostgreSQL1000... ORDER BY created_time DESC LIMIT 1000applied
SELECT id FROM ordersMySQL1000SELECT id FROM orders LIMIT 1000applied
SELECT id FROM ordersSnowflake1000SELECT id FROM orders LIMIT 1000applied
SELECT id, total FROM orders ORDER BY created_time DESCSQL Server1000... ORDER BY created_time DESC OFFSET 0 ROWS FETCH NEXT 1000 ROWS ONLYapplied
SELECT id FROM ordersAzure Synapse1000SELECT TOP 1000 id FROM ordersapplied
SELECT id FROM orders LIMIT 50PostgreSQL1000unchangedalready_limited
SELECT id FROM orders LIMIT 10 OFFSET 20PostgreSQL1000unchangedalready_limited
SELECT TOP 50 id FROM ordersSQL Server1000unchangedalready_limited
SELECT id FROM orders LIMIT 5000000PostgreSQL1000SELECT id FROM orders LIMIT 1000own_bound_capped
SELECT id FROM orders LIMIT ALLPostgreSQL1000SELECT id FROM orders LIMIT 1000own_bound_capped
SELECT id FROM orders FETCH FIRST 5000000 ROWS ONLYPostgreSQL1000... FETCH FIRST 1000 ROWS ONLYown_bound_capped
SELECT TOP 5000000 id FROM ordersSQL Server1000SELECT TOP 1000 id FROM ordersown_bound_capped
SELECT TOP 10 PERCENT id FROM ordersSQL Server1000the statement wrapped: SELECT TOP 1000 * FROM ( newline the original newline ) AS beacon_rowsown_bound_capped
SELECT id FROM orders LIMIT (SELECT 5000000)PostgreSQL1000wrapped: SELECT * FROM ( … ) AS beacon_rows LIMIT 1000own_bound_capped
WITH x AS (SELECT a FROM dbo.t) SELECT TOP 100 PERCENT a FROM xSQL Server, cap 100blockeduncappable_bound

The last row is blocked because T-SQL cannot put a WITH clause inside a derived table, so a bound that cannot be lowered cannot be wrapped either. The message is: The statement bounds its own rows in a way the row cap cannot check or place (an expression, PERCENT or WITH TIES). Bound it with a number of at most 100 rows, or remove the bound. A cap of zero or less is refused (invalid_row_cap: The row cap must be at least 1 row.), and a statement nested too deeply to cap is refused (too_deep). A statement that carries no result set gets not_applicable.

If the SQL did not parse (possible only when read-only enforcement is off, because the AST validator refuses unparseable SQL otherwise), the cap is placed by a textual heuristic, the verdict is textual_fallback and a Warning is logged with the dialect and parse error, never the SQL text.

What happens to a result that is larger than the cap depends on who asked.

CallerCap comes fromA larger result
Previews, subscriptions, AI actor checks, ad-hoc queries, data contract rules (GatedSqlRunner, QueryService)Beacon:Query:MaxExecutionRows (default 100,000)The run fails. It is never cut short.
Migration readsBeacon:Migrations:MaxRows (default 100,000)The run fails before anything is written.
MCP query toolmax_rows argument (default 100), clamped to the project’s MaxRowLimit (stored MCP setting, default 1000), which is itself bounded by Beacon:Mcp:Ceilings:MaxRowLimitThe SQL is cut at the cap. The tool says so: Row cap of 1000 reached — the result set may be truncated.

The failing message for the first group names the setting:

Step 2 returned more than 100000 rows (the Beacon:Query:MaxExecutionRows limit); filter or aggregate it so the result fits.

On PostgreSQL, MySQL, SQL Server, Azure Synapse and Snowflake the read also stops one row past the cap, so the database driver never holds a larger result in memory. BigQuery stops reading the job’s pages there and Databricks is sent the cap as the statement’s row_limit. The provider’s own message is: The query returned more than N rows, so its read was stopped and the result discarded; filter or aggregate it so the result fits.

The gate’s parser checks are the main control. The data source adds a second one where the engine allows it. IDataSourceProvider.SupportsDatabaseReadOnlyEnforcement reports honestly which engines have it, and the data source shows a badge, with a Warning logged at startup and on save, where it is false.

EngineSupportsDatabaseReadOnlyEnforcementWhat the read-only path does
PostgreSQLtrueSET default_transaction_read_only = on on the session, a READ ONLY transaction, and the statement sent as a batch of exactly one command, so the driver refuses a second statement
MySQLtrueSTART TRANSACTION READ ONLY on a connection with statement batches off
SQL ServerfalseRuns in a transaction that is always rolled back. A write the parsers missed is undone, not refused
Azure SynapsefalseParser gates and the read-only login only
SnowflakefalseParser gates and the read-only login; also a session STATEMENT_TIMEOUT_IN_SECONDS
BigQueryfalseThe connector’s own parser check, the configured project, and a dry run whose statement type must be SELECT
DatabricksfalseThe connector’s own parser check and the configured catalog; the token’s Unity Catalog grants remain the database’s own limit

On SQL Server, a statement that ends the rolled-back transaction (a COMMIT or ROLLBACK in the batch, detected with @@TRANCOUNT and a savepoint only Beacon knows) fails the run, discards its rows and logs a Warning. The caller sees: The query ended the transaction it runs in, so its result was discarded. Only a single SELECT statement may run.

Event idNameLevelMeaning
7116ReadOnlyTransactionEndedWarningA read-only query on a SQL Server data source ended its rolled-back transaction. The log line carries the data source id only.

Bound from appsettings.json or the environment. These apply to the statements Beacon runs for its own features.

KeyTypeDefaultRangeWhat it does
Beacon:Query:MaxExecutionRowsint1000001 to 10,000,000The row cap written into the SQL of every statement of a preview, subscription run, AI actor check or ad-hoc query. A larger result fails the run. Every row is held in memory, so raise it with care.
Beacon:Query:StatementTimeoutSecondsint1201 to 3,600How long one such statement may run before it is cancelled. A subscription’s own timeout may only be shorter.
Beacon:Query:MaxResultByteslong268435456 (256 MiB)greater than 0The most bytes one result may hold while it is read from PostgreSQL, MySQL, SQL Server, Azure Synapse or Snowflake, and from the in-memory join. Estimated as rows arrive. A larger result fails the run.
Beacon:Migrations:MaxRowsint1000001 to 10,000,000A migration run’s own row budget, in place of Beacon:Query:MaxExecutionRows.
Beacon:DataSources:BigQuery:MaxBytesBilledlongnoneat least 1 when setThe most bytes one BigQuery query job may bill. A data source’s own MaximumBytesBilled (default 10 GiB) is lowered to it.

An out-of-range value fails startup with a message such as Beacon:Query:MaxExecutionRows must be between 1 and 10000000.

A warehouse data source stores its own QueryTimeoutSeconds in its connection settings (BigQuery, Databricks, CloudWatch). Whatever is stored, one statement waits at most 900 seconds, and a value of zero or less means 300 seconds. BigQuery jobs and Databricks statements are cancelled on the warehouse when the wait ends.

{
"Beacon": {
"Query": {
"MaxExecutionRows": 50000,
"StatementTimeoutSeconds": 60,
"MaxResultBytes": 134217728
},
"Migrations": { "MaxRows": 500000 },
"DataSources": {
"BigQuery": { "MaxBytesBilled": 5368709120 }
}
}
}

The same in environment variables:

Terminal window
Beacon__Query__MaxExecutionRows=50000
Beacon__Query__StatementTimeoutSeconds=60
Beacon__Query__MaxResultBytes=134217728

Deployment locks pin a setting for every project, and an Admin cannot change it (the UI disables the switch and the API answers 409). Ceilings bound the numeric MCP settings: a stored value above a ceiling resolves to the ceiling.

KeyTypeDefaultRangeWhat it does
Beacon:Mcp:ForceReadOnlybooltrueMakes the gate enforce read-only whatever a caller or stored setting says. Set false only to let an Admin switch read-only enforcement off at runtime.
Beacon:Mcp:Ceilings:MaxSqlCharsint100000greater than 0The longest SQL text the gate evaluates (stage 1). Always applies.
Beacon:Mcp:Ceilings:MaxRowLimitintnonegreater than 0Upper bound for the project’s MaxRowLimit MCP setting (default 1000, range 1 to 10,000,000).
Beacon:Mcp:Ceilings:StatementTimeoutSecondsintnonegreater than 0Upper bound for the project’s MCP statement timeout (default 30, range 1 to 3,600).
Beacon:Mcp:Ceilings:MaxResultBytesintnonegreater than 0Upper bound for the size of the result an MCP tool returns to its client (default 262,144 bytes).
Beacon:Mcp:Ceilings:MaxExplainCostdecimalnonegreater than 0Upper bound for the PostgreSQL planner cost a statement may have. The statement is planned with EXPLAIN, never run, and refused above the limit.
Beacon:Mcp:Ceilings:MaxConcurrentQueriesPerKeyintnonegreater than 0Upper bound for concurrent queries per caller (default 4). A query over the limit is refused at once, never queued.

A refusal for cost reads: The query's estimated cost (1250000) exceeds this project's limit (100000). Narrow the query, add filters, or ask an administrator to raise MaxExplainCost. A refusal for concurrency reads: Too many concurrent queries for this credential; retry shortly. The values in the cost message are the planner’s numbers and your limit.

{
"Beacon": {
"Mcp": {
"ForceReadOnly": true,
"Ceilings": {
"MaxSqlChars": 20000,
"MaxRowLimit": 1000,
"StatementTimeoutSeconds": 30,
"MaxExplainCost": 500000,
"MaxConcurrentQueriesPerKey": 4
}
}
}
}
Terminal window
Beacon__Mcp__ForceReadOnly=true
Beacon__Mcp__Ceilings__MaxRowLimit=1000
KeyTypeDefaultRangeWhat it does
Beacon:RowSecurity:Enabledboolfalsefalse onlyA deployment lock. Setting it to true fails startup, see Stage 7.

The tool returns an error result (isError: true) with a text block. For query, the text is Query validation failed: followed by the gate’s reason:

Query validation failed: pg_stats is a system catalog relation: SQL may read the data source's own tables only, not the engine's catalog, statistics or query history. Beacon lists the source's tables and columns from its own metadata.

A statement refused by the schema check names the unknown column or table. A statement that was allowed and then failed on the database reads Query execution failed: followed by the database’s error, which Beacon redacts while PII detection is on (the error can quote row values). Every call, including a refused one, is written to the MCP audit with the reason (see MCP server). A successful tools/call result ends with a separate notice block saying the content is data, not instructions.

Beacon’s REST endpoints (query preview, step preview, ad-hoc runs) call the same gate. A refusal is an InvalidOperationException thrown by Beacon, which the API maps to 400 with the gate’s message as the title, as application/problem+json:

POST /beacon/api/queries/42/preview
{
"type": "/errors/invalid-operation",
"title": "pg_stats is a system catalog relation: SQL may read the data source's own tables only, not the engine's catalog, statistics or query history. Beacon lists the source's tables and columns from its own metadata.",
"status": 400
}

An over-cap result and a timeout of a final query are reported as 400 the same way, with /errors/beacon as the type (for example The final query timed out.). Only text that Beacon itself throws reaches the caller. A library’s exception is a 500 with no detail, logged by its type and code only.

The gate logs identifiers and counts only. The row-cap textual fallback and the SQL Server rolled-back transaction (event 7116) log a Warning. No SQL text, row value or connection string is logged.

A statement refused by the gate never reaches the data source, so it has no execution log row. See the execution log.

Every statement that passes the gate and runs for a Beacon feature is recorded in the execution log (ManualQueryExecutionLog) before it is sent, with status Started, and its row is closed afterwards with how it ended (succeeded, failed, cancelled, timed out). A row that stays Started is a statement whose end was never recorded. The row holds the data source, the SQL as sent (placeholders, never parameter values), the result count, the duration, TriggeredByUserId (a Users.Id, never a name) and the context that ran it: QueryStep, QueryStepPreview, SubscriptionStep, ColumnValueSample, DocumentationEnumDiscovery, DataQualityRule or GoldSqlReplay (the gold SQL a golden-case promotion runs once). A failure is recorded as the database’s error redacted as with PII detection on, whatever the caller’s setting. Reads and exports mask the SQL’s literals.

KeyTypeDefaultRangeWhat it does
Beacon:Audit:ExecutionLog:RequiredboolfalseOff: a statement whose Started row cannot be written still runs, and a Warning is logged. On: it does not run, and the caller gets an error. On, startup fails when no execution log is registered.
Beacon:Audit:ExecutionLog:RetentionDaysintnone (keep forever)greater than 0 when setRows older than this are deleted by the execution log retention job, which the host schedules.
{
"Beacon": {
"Audit": {
"ExecutionLog": { "Required": true, "RetentionDays": 365 }
}
}
}

The MCP tools write to the MCP audit instead of the execution log. The execution log, its sealing and its export are described in Security audit trail.

SettingDevelopmentProductionBeacon:Profile = Regulated
Beacon:Mcp:ForceReadOnlytruetrueRequired true
Beacon:Query:MaxExecutionRowsdefault100,000 or lowernot judged
Beacon:Query:StatementTimeoutSecondsdefault120 or lowernot judged
Beacon:Mcp:Ceilings:MaxRowLimitunsetset (for example 1000)Filled with 1000 when unset
Beacon:Mcp:Ceilings:StatementTimeoutSecondsunsetset (for example 30)Filled with 30 when unset
Beacon:Mcp:Ceilings:MaxResultBytesunsetsetFilled with 262144 when unset
Beacon:Mcp:Ceilings:MaxConcurrentQueriesPerKeyunsetsetFilled with 4 when unset
Beacon:Mcp:Ceilings:MaxExplainCostunsetset on PostgreSQL sourcesnot judged
Beacon:Audit:ExecutionLog:RequiredfalsetrueFilled with true when unset, required true
Beacon:RowSecurity:Enabledunsetunsetunset
Read-only database loginrecommendedrequired in practicerequired in practice

The regulated profile fills only keys your configuration leaves unset and never overrides a value you set. A value weaker than the profile requires fails startup, with every finding listed in one message. See Regulated profile and Deployment locks.

SymptomCauseFix
Write operations are not allowed. Only SELECT queries are permitted.The statement contains a write command (DELETE, DROP, INSERT, EXECUTE and similar), also after a ;. A keyword inside a string literal, a comment or a quoted column name does not trigger it.Send a read-only SELECT. Make the change in your own tooling, not through Beacon.
Multiple SQL statements are not allowed. Submit a single SELECT query.Two statements in one request, for example SELECT 1; SELECT 2.Send one statement per call. One trailing ; is accepted.
The function X is not allowed in read-only SQL: it reaches files, other servers or settings, or holds resources.The function is on the refusal list.Use a table or view instead. The list is fixed; there is no setting to allow a function.
... is a system catalog relation ...The statement reads pg_stats, information_schema, sys.* and similar.Ask for the data through the documented tables. Use get_context or the schema browser for table and column names.
The SQL qualifies a name with a database, but this data source has no database configuredThe connection string has no database, or Beacon cannot read it.Name the database in the connection (Database=), or write schema.table.
Query validation failed: Column 'x' does not exist on 'orders'. Available: ... from queryThe schema check blocks on unknown names.Use a column from the list in the message, or scan the source again if the schema changed.
This data source has no extracted metadata (it was never scanned, metadata loading is off, or the scan found no tables); query it through MCP once it has metadata. from queryempty_catalog: nothing to check the SQL against.Run a metadata refresh.
The SQL dialect of this data source is not knownThe data source type maps to no dialect.Check the data source’s engine setting.
Beacon:Query:MaxExecutionRows must be between 1 and 10000000. at startupA value out of range.Correct the key.
Beacon:RowSecurity:Enabled cannot be turned on at startupThe lock was set to true.Remove the key.
Run fails with returned more than N rowsThe result is over Beacon:Query:MaxExecutionRows.Filter or aggregate. Raise the cap only if memory allows.
The result is larger than the N-byte limit (Beacon:Query:MaxResultBytes)Many wide columns.Select fewer columns or rows.
Event 7116 in the logA SQL Server query tried to end its transaction.Review who sent the statement. Move the login to read-only.