# How to Use AI for Coding Without Breaking Production

URL: https://upstreamapi.com/journal/how-to-use-ai-for-coding
Type: blog
Locale: en
Published: 2026-12-05
Updated: 2026-12-05

---

> A practical workflow for using AI for coding on a platform team: write the spec, let tests judge, cap the diff, and ship behind a flag with an SLO gate.

How to use AI for coding without breaking production comes down to three habits: hand the assistant small, specced tasks, make tests the judge instead of your eyes, and ship its output behind a flag with an SLO gate. The 3 a.m. page that follows a 900-line AI diff is rarely the model's fault. It is a rollout problem. This guide covers the workflow we see holding up in teams of 50 to 500 engineers.

## Start with the task, not the tool

Most advice on AI coding opens with a tool ranking. That is the wrong first decision. The first decision is what you are asking for, because the failure rate of an assistant tracks task size far more than model choice.

Three task shapes work reliably today:

- 
**Bounded edits**: rename a parameter across a module, add a field to a DTO, convert a callback to async/await.

- 
**Test scaffolding**: generate table-driven cases for a function that already exists and already has a spec.

- 
**Glue code**: the retry wrapper, the pagination loop, the config parser nobody wants to write twice.

Three shapes fail often enough that we treat them as opt-in with a second reviewer: auth and permission changes, anything touching money, and schema migrations. The model has no idea what your blast radius is. You do.

Skip "build me the whole service" prompts. They produce code that compiles, passes a happy-path demo, and carries assumptions nobody wrote down. That is how you end up reading a diff for an hour and still not knowing what it does.

## Write the spec before the prompt

The single highest-leverage habit is a half-page spec before you open the assistant. Not a prompt. A spec: inputs, outputs, error behavior, what must not change, and the performance budget.

A useful template for a platform team:

- 
**Goal**: one sentence, with the observable behavior.

- 
**Constraints**: language version, libraries already in use, no new dependencies.

- 
**Invariants**: what existing tests must keep passing.

- 
**Failure behavior**: timeouts, retries, what the caller sees when it breaks.

- 
**Out of scope**: the files and modules the assistant must not touch.

Paste that, plus the two or three files that define the surrounding conventions. Context beats cleverness. An assistant that sees your error-handling pattern will copy it. One that does not will invent its own, and you will find out in review or in prod.

![Laptop with a small code diff next to a handwritten review checklist](https://fdzlnqpwsaniezitwiuw.supabase.co/storage/v1/object/public/cms-media/upstreamapi/2026-12/9c1ca4-inl1.webp)

## Which assistant fits which job

Pick the mode by the size of the change, not by brand loyalty. Inline completion suits the 10-line edit where you already know the answer. An agent that reads the repo and runs commands suits multi-file work where the cost is navigation, not typing.

Cursor is the IDE-native option: fast for in-editor edits and multi-file changes you watch happen. Worth it if your team lives in the editor and wants to see every hunk before accepting it. Skip it if your reviewers insist on terminal-driven, scriptable workflows.

Claude Code runs in the terminal and works through a task with the repo, the test runner, and git. It suits larger refactors where you want the agent to run the suite and iterate until it is green. The tradeoff is that you give up the constant inline visibility, so your review discipline has to be stronger, not looser.

GitHub Copilot is the lowest-friction path for an org already on GitHub: completions, chat, and pull request summaries inside the workflow your team already has. It is the easy default for procurement. It is rarely the sharpest tool for a large refactor.

If you are choosing between two of these, we already ran the numbers in our [Cursor vs GitHub Copilot comparison](/journal/cursor-vs-github-copilot). Do not spend a week on this decision. Pilot two tools on the same ticket and compare the diffs.

## Let tests be the judge

Here is the habit that separates teams who ship AI code safely from teams who ship it nervously: the tests exist before the assistant writes the implementation.

Write the failing test first, or have the assistant write it from your spec and review that instead. Then ask for the implementation. The loop is short. The assistant proposes, the suite runs, the red tells it what it got wrong. You read the test, which is small, instead of the implementation, which is not.

A minimal example in Go. You write the contract:

`func TestBackoff(t *testing.T) {
    cases := []struct {
        attempt int
        want    time.Duration
    }{
        {0, 100 * time.Millisecond},
        {1, 200 * time.Millisecond},
        {5, 3200 * time.Millisecond},
        {20, 30 * time.Second}, // capped
    }
    for _, c := range cases {
        if got := Backoff(c.attempt); got != c.want {
            t.Errorf("attempt %d: got %v want %v", c.attempt, got, c.want)
        }
    }
}`The assistant fills in `Backoff`. The cap at 30 seconds is the line that matters, and it is the line a model most often forgets, because nothing in a happy-path prompt mentions it. A test that pins the cap catches it in two seconds.

Two caveats. First, do not let the assistant write both the test and the code from the same ambiguous prompt, because it will agree with itself. Second, mutation-style spot checks help: change one operator in the implementation and confirm a test goes red. If nothing fails, the suite was decoration.

## What the research says about speed

The honest answer on productivity is mixed. In a randomized trial, [METR measured experienced open-source developers](https://metr.org/blog/2025-07-10-early-2025-ai-experienced-os-dev-study/) working on their own repositories and found they took 19% longer with AI tools than without, while believing they were faster. That study covered early-2025 tools and a narrow population, and METR itself cautions against generalizing it.

The useful reading is not "AI is slow". It is "your sense of speed is a bad instrument". Measure cycle time and change failure rate on real tickets for a month, per team, before you write the business case.

![Sticky notes on a glass wall arranged as concentric rollout stages](https://fdzlnqpwsaniezitwiuw.supabase.co/storage/v1/object/public/cms-media/upstreamapi/2026-12/3586d2-inl2.webp)

## The review step is where teams get hurt

The [2025 DORA report on AI-assisted development](https://blog.google/innovation-and-ai/technology/developers-tools/dora-report-2025/) puts adoption at 90% of surveyed professionals, and reports that roughly 30% trust AI-generated code only a little or not at all. DORA's framing is that AI amplifies the system around it. Strong pipelines get faster. Weak ones get faster at producing incidents.

That matches what we see in post-mortems. The incident rarely traces to a hallucinated API. It traces to a reviewer who approved a large, plausible-looking diff because it read well.

Rules that hold up:

- 
**Cap the diff.** If an AI-assisted PR is over 400 changed lines, split it. Reviewer attention is the scarce resource.

- 
**Label AI-assisted PRs.** Not for blame. For measurement. You cannot compare failure rates if you cannot see which changes had help.

- 
**Same gates for everyone.** Linters, type checks, secret scanning, dependency review. The assistant does not get a fast lane.

- 
**Review the prompt too.** For anything non-trivial, paste the spec into the PR description. The reviewer needs to know what was asked.

The post-mortem will ask what the author understood. If the answer is "the model wrote it", you have a process gap, not a model gap.

## Ship AI-written code behind a flag

This is the part most "how to use AI for coding" guides skip, and it is the part that decides whether a bad diff costs you a minute or a Saturday.

Treat AI-assisted changes as higher-variance changes. You do not need to distrust them. You need to size the blast radius before they reach everyone.

A feature management platform such as LaunchDarkly gives you the mechanism: wrap the new path in a flag, roll it to 1%, then 5%, then 25%, and hold each ring until the numbers say continue. The flag is also your revert. Flipping it off takes seconds. A redeploy takes minutes and a pipeline you hope is green.

![Breaker panel with one toggle switch flipped down like a kill switch](https://fdzlnqpwsaniezitwiuw.supabase.co/storage/v1/object/public/cms-media/upstreamapi/2026-12/8edbce-inl3.webp)

The gate is what makes it a rollout instead of a slow deploy. Define it before you ship:

- 
**Pick the SLI** closest to the change: error rate on the endpoint, p99 latency, queue depth.

- 
**Set the threshold** from your SLO budget, not from a gut feeling. If the budget burns 10x faster than baseline in the 1% ring, stop.

- 
**Automate the stop.** A human watching a dashboard at 2 a.m. is not a control. A rule that flips the flag back is.

This is the same logic behind a [canary deployment](/journal/what-is-canary-deployment): small exposure, a measurable signal, an automatic exit. The assistant wrote the code in ten minutes. The rollout is what earns it the right to reach everyone.

## A weekly loop that keeps you honest

Adopting this without a feedback loop means drifting back to old habits within a month. A lightweight loop:

- 
**Monday**: pick two or three tickets suitable for assistant work using the three safe shapes above.

- 
**During the week**: label AI-assisted PRs, keep each one under the diff cap, and flag every rollout.

- 
**Friday**: look at four numbers per team: lead time for changes, change failure rate, time to restore, and review time per PR. Compare labeled and unlabeled changes.

If change failure rate for labeled PRs is higher after a month, the answer is rarely "ban the tool". It is usually smaller diffs, stronger specs, or a tighter gate. If it is lower, widen the scope one task shape at a time.

## What we would actually do on Monday

If you have a platform team and no policy yet, do these five things this week:

- 
Write the half-page spec template and put it in the repo.

- 
Add an `ai-assisted` PR label and a 400-line soft cap.

- 
Require a failing test before the implementation for any assistant-written logic.

- 
Put the first AI-heavy change behind a flag with a single SLI gate.

- 
Schedule the Friday review for the next four weeks.

That is it. No tool migration, no policy document nobody reads. The assistant is a fast, confident colleague with no memory of your last incident. Your process has to remember it for them.

Which part of your pipeline would catch a plausible, wrong diff today: the review, the tests, or the rollout?

## FAQ

### What is the best way to use AI for coding?

Write a short spec, give the assistant a small bounded task plus the files that define your conventions, and let a failing test verify the result. Review the diff as you would any human PR, and ship it behind a flag.

### Is AI-generated code safe to ship to production?

It is safe when it passes the same gates as human code and reaches users gradually. Run linters, type checks and secret scans, then roll out behind a feature flag with an automatic rollback tied to an SLO.

### Does AI actually make developers faster?

Evidence is mixed. A METR randomized trial found experienced open-source developers took 19% longer with early-2025 tools while believing they were faster. Measure cycle time and change failure rate on your own tickets.

### Which tasks should I avoid giving to an AI assistant?

Be cautious with auth and permission changes, anything touching money, and schema migrations. These have a large blast radius and need a second human reviewer who understands the system.

### How big should an AI-assisted pull request be?

Keep it under roughly 400 changed lines. Past that, reviewers skim, and plausible but wrong code gets approved. Split large changes into steps that each have their own tests.

### Should I label AI-assisted pull requests?

Yes, for measurement rather than blame. Labels let you compare change failure rate and review time between assisted and unassisted changes, so you can widen or tighten usage with data.