Skip to main content

How do I go from a spec to working, tested code using AI agents?

Summary

  • Write the spec so the agent can check its own work: intent, inputs and outputs, constraints, and acceptance tests. Then let it loop: generate code, run the tests, read the failures, and fix.
  • Genie Code is the AI coding and data assistant in the Databricks workspace. In agent mode it plans a solution, runs code, uses the outputs to improve its results, and fixes errors, within your Unity Catalog permissions.
  • To build your own coding agent, use Agent Bricks, the Databricks agent developer platform. The Agent Bricks CLI and Databricks Sandbox, where an agent can run the code it writes in isolation, are both in Beta.
  • Passing tests is necessary but not sufficient. Keep CI and a human review in front of every merge, and keep Genie Code's auto-approve off when you work with production data.

How do I go from a spec to working, tested code using AI agents?

Write the spec so that it can be checked: state what the code must do, what it takes and returns, and the constraints, then turn the key behaviors into tests. Let the agent loop through generating code, running the tests, reading the failures, and fixing until they pass. A person reviews the result before it ships.

What does the loop look like?

  1. Write the spec as tests. Describe the intent in a few sentences, then encode the behaviors that matter as acceptance tests the agent can run. Put standing rules, such as coding standards, in Genie Code's user and workspace instructions or in reusable skills.
  2. Let the agent plan, generate, and run. Genie Code in agent mode "automates multi-step workflows, plans solutions, retrieves relevant assets, runs code, uses cell outputs to improve results, and fixes errors automatically".
  3. Verify outside the agent. Run the same tests in CI. Declarative Automation Bundles describe jobs and pipelines as source files, and a bundle includes unit tests and integration tests. Databricks Connect runs Spark code on Databricks compute from your IDE.
  4. Review and trace. A person reviews the diff. For a custom agent, MLflow Tracing records each step the agent takes, which helps you debug its behavior.

A spec can be as small as one test:

# tests/test_dedupe_orders.py
from orders import dedupe_orders

def test_keeps_latest_record_per_order():
    rows = [
        {"order_id": 1, "updated_at": "2026-10-01", "status": "open"},
        {"order_id": 1, "updated_at": "2026-10-02", "status": "shipped"},
    ]
    assert dedupe_orders(rows) == [rows[1]]

Which Databricks tools do which job?

Job Tool What the docs say
Write and run code in the workspace Genie Code The AI coding and data assistant. It runs in notebooks, the SQL editor, the Lakeflow Pipelines Editor, AI/BI dashboards, and MLflow
Build your own coding agent Agent Bricks The agent developer platform for developers who write code. The Agent Bricks CLI is in Beta
Run generated code in isolation Databricks Sandbox (Beta) Runs untrusted code in an isolated environment, including AI-written code
See what the agent did MLflow Tracing Records each step the agent takes
Govern models and tools Unity Gateway Governs access to models, MCP servers, and skills, with rate limits, guardrails, and usage tracking
Test and ship Declarative Automation Bundles Source control, code review, testing, and CI/CD for data and AI projects

How do I keep generated code away from sensitive data?

Genie Code "is governed by your Unity Catalog permissions, so it can only access data and perform operations that you have permissions for." Its approval options are Ask every time, Allow in current chat, Always allow, and Auto-approve. The docs state that "Auto-approve is a productivity feature, not a security boundary" and advise keeping it off for production data and sensitive workspaces.
For a custom agent, tools can run with the permissions of the app's service principal or of the user who sent the request. To give generated code a sandbox (Beta) with limited data access, add the tool with scopes:

agentbricks tools add sandbox --scope table:samples.nyctaxi.trips

By default the sandbox runs with the permissions of the user who sent the request. Add --auth app to use the app's service principal instead. Plan for one limit: the docs say there are no restrictions on network egress from a sandbox, and egress is not configurable. MCP tools are gated separately, by EXECUTE grants on each MCP service.

FAQs

How detailed should the spec be?

Give the agent the intent, the inputs and outputs, the constraints, and tests for the behaviors that matter. Describe what the code must do, not how to write it. Too little detail leaves the agent guessing.

What if the tests pass but the code is wrong?

Tests only check what they encode. Write a failing test that captures the bug, let the agent fix it, and keep human review for anything that touches production.

Can the agent use my own tools?

Genie Code can connect to external tools using MCP servers and built-in connectors. Custom agents on Agent Bricks can call Databricks-managed, custom, and external MCP servers. Unity Gateway governs MCP access with grants, tool selection, and rate limits.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.