AI Coding Agents for SQL: Real Limits Beyond Lower Prices
Lower API prices make AI coding agents cheaper to try, but they do not make complex SQL reliable. This article explains how data teams should separate cost from correctness, evaluate constraint decay across layered SQL tasks, and put generation behind checks, tests, plan review, and audit.
For a while, the most visible change in AI coding agents has been price. Some model providers have cut API prices sharply to win developer adoption with lower call costs. At the same time, the industry keeps discussing the limits of agent capability. For data teams, these are two different facts: prices are falling, and reliability on complex tasks is still insufficient. Asking an agent to write a simple SELECT is not hard. Asking it to follow naming standards, permission models, audit requirements, partition pruning rules, and cost limits while generating a multi-table JOIN is often unstable.
This article does not discuss any vendor’s promotion. It treats the issue as a general engineering question: once an AI coding agent enters a real data-development workflow, how should a team evaluate it, constrain it, and choose between cost and reliability?
1. Lower prices do not mean higher usability
A large drop in API prices is clearly helpful for high-frequency workloads. Tasks such as data development, report generation, SQL review, and metadata completion often need multiple rounds of context, so token use is not trivial. Caching, batch calls, and prefix reuse can also push the cost of a unit of work much lower. Cost optimization answers whether a call is expensive. It does not directly answer whether the result is correct.
On simple tasks, model capability and cost are almost linearly related. Syntax completion, single-table queries, field explanations, and error summaries are usually within the reach of lower-priced models. On complex tasks, the cost of failure grows quickly. A wrong JOIN can distort a metric. A missing permission filter can create a data-leakage risk. A query without partition pruning can overload compute. At that point, cheap is no longer the only metric. Verifiability, constraint compliance, and observability matter more.
When choosing a tool, a data team should at least split the problem into three layers:
- Generation: Can the model understand table structure, field meaning, business definitions, and task intent?
- Constraints: Can it follow naming standards, permission rules, audit requirements, and cost limits?
- Verification: Can the team prove the result is usable through static checks, execution-plan review, test cases, and human sampling?
A price war lowers the barrier to the first layer. The second and third layers decide whether an agent can enter production.
2. Constraint decay: why complex SQL fails
Public research has noted a pattern worth attention: as structured constraints accumulate, an agent’s task pass rate drops significantly. This can be summarized as constraint decay. The more constraints there are, and the more they intersect, the more likely the model is to drop a requirement somewhere. This is not simply “the model cannot write SQL.” It is that the model cannot reliably hold every constraint when objectives conflict.
In data development, production SQL often carries all of the following constraints at once:
- Naming: Table aliases, field aliases, and temporary table names must follow team standards.
- Metric definitions: Amount units, time definitions, status enums, and deduplication logic must match the metric definition.
- Permissions: Row-level permission filters must be included, and unauthorized databases or tables must not be accessed.
- Audit: Critical queries must retain source, task identity, and operation logs.
- Performance: Large tables must be partition-pruned, Cartesian products must be avoided, and scan volume must be limited.
- Security: Sensitive fields must be masked or excluded from the result set.
- Maintainability: Use layered CTEs, comments, and formatting, and avoid repeated subqueries.
Each rule is manageable alone. Together, the model easily satisfies one and misses another. It may join the tables correctly but omit a row-level permission condition. It may prune partitions but break the deduplication logic required by the metric. Worse, these errors are often syntactically valid and run successfully while returning the wrong result. That is one of the hardest classes of defect to find.
-- Example: a query that looks correct but lacks permission filtering and partition pruningSELECTc.customer_id,c.customer_level,SUM(o.paid_amount) AS paid_amountFROM dim_customer cJOIN fact_order oON c.customer_id = o.customer_idWHERE o.status = 'PAID'GROUP BY c.customer_id, c.customer_level;
The SQL above is syntactically fine. If the team also requires date partition pruning, exclusion of test customers, and filtering by the current user’s permissions, it is not acceptable. An agent that only focuses on “writing the JOIN” will ignore those production constraints.
3. From framework sensitivity to data development
Research also suggests a pattern: agents usually perform better in environments with few rules and weak conventions, and worse in environments with strong conventions and many implicit rules. The same pattern applies to data development.
A simple query is a minimal-convention environment: a table schema goes in, a single-table aggregation comes out, constraints are few, and the model is more likely to be correct. A complex warehouse query is a strong-convention environment. Metadata, permissions, metric definitions, audit rules, and performance rules are intertwined, and the model must balance several goals. A natural-language instruction such as “please follow the standards” is not enough. Implicit standards must become explicit checks.
A practical approach is to split constraints into three types:
- Hard constraints: Permissions, security, compliance, and partition pruning must be blocked by a validator.
- Soft constraints: Naming style, comments, and formatting can be handled by rule checks and human review.
- Business constraints: Metric definitions, status enums, and deduplication logic need both test cases and definition documents.
The agent can draft SQL. It cannot replace the validator. A more reasonable flow is generate, validate, repair, and review: the model drafts the SQL, static rules check hard constraints, test cases check business definitions, execution-plan review checks performance risk, and a human sample review comes last.
4. How to evaluate an AI coding agent
Evaluation should not stop at “can it write a SQL statement.” Build a layered task set. A data team can use four kinds of tests:
- Basic syntax: Single-table queries, aggregation, window functions, and date handling, to confirm a minimum capability.
- Stacked constraints: Add naming standards, permission filters, partition pruning, and masking to the basic tasks, and watch how the pass rate decays.
- Long context: Provide multi-table metadata, metric-definition documents, and historical SQL, and test whether the model retrieves and cites them correctly.
- Regression repair: Give an error message or a wrong result, and ask the model to locate and fix it, to test whether it can iterate.
Metrics should also be layered:
- Syntax correctness: Whether the statement passes a parser.
- Constraint compliance: Whether every hard constraint is met.
- Business correctness: Whether results match definition tests.
- Repair success: Whether multi-round feedback converges.
- Cost and latency: Tokens per task, number of calls, and human review time.
- Observability: Whether generation records, validation results, and change history are retained.
Only when these metrics sit in the same comparison can a team avoid being misled by a low price or a single demo.
5. Putting it into practice: make constraints executable
To make an agent genuinely usable in data development, the key is not a longer prompt. It is engineering the constraints. Start with these steps.
First, make constraints explicit. Write naming standards, permission rules, partition fields, sensitive fields, and forbidden-table lists as machine-readable rule files, not as scattered documents and verbal habits.
# Example constraint list (pseudo-configuration)naming:table_alias: snake_casefield_alias: snake_casesecurity:require_row_level_filter: trueforbidden_tables: ["*_test", "*_tmp"]performance:require_partition_filter: truepartition_field: dtaudit:require_task_id: truerequire_comment: true
Second, structure the context. Give the agent table schemas, field meanings, metric definitions, example SQL, and permission mappings, not only a natural-language request. The more structured the context, the more stably the model can cite it.
Third, run static checks first. Use a parser to check syntax, table names, field names, partition conditions, permission filters, and sensitive fields. If validation fails, block the query before execution.
# Pseudocode: SQL constraint validatordef validate_sql(sql, context):errors = []if not has_partition_filter(sql, context.partition_field):errors.append("Missing partition pruning condition")if not has_row_level_filter(sql, context.user_scope):errors.append("Missing row-level permission filter")if contains_forbidden_table(sql, context.forbidden_tables):errors.append("Access to a forbidden table")return errors
Fourth, review the execution plan. For complex queries, check for full-table scans, Cartesian products, and oversized intermediate results. The agent produces text. What actually consumes resources is the execution plan.
Fifth, use a sandbox and an audit trail. Run every agent-generated query in an isolated environment first, and keep the task identity, generation record, validation result, and change history. When building a data-development platform on Baidu AI Cloud, the model service is only one part of the system. Permissions, audit, metadata, and monitoring need to be designed as shared capabilities so the agent can enter a process that can be governed and controlled.
6. Selection advice and conclusion
Back to the original question: under a price war, how should a data team choose an AI coding agent?
Use three checks:
- Check the boundary. Decide which tasks the agent may generate and which must be written by people. High-risk work such as permissions, security, and core financial definitions should stay human-led, with the agent assisting.
- Check verification. Prefer a setup that can connect static checks, test cases, execution-plan review, and audit logs. An agent without a closed verification loop can demo, but it should not enter production.
- Check the full cost. Do not compare only the price per million tokens. Compare the cost of one usable task, including generation, validation, repair, and human review.
The conclusion is clear. AI coding agents have real value for SQL, and their limits are equally real. Lower prices speed up trials, but they do not remove constraint decay. What a data team needs to build is not a model that never makes mistakes. It is a system in which the model works under checks that can validate, block, and audit. When constraints are explicit, validation is automated, and risk is isolated, an agent can move from a demo that can write SQL to a productivity tool that can take part in data development.
