r/SQL • • Aug 25 '26

Discussion How are folks QA’ing AI agents?

Lots of folks at my company use Claude Code to do analysis. When I ask whether the query is right, I get wishy washy responses at best. Anybody have good tools or processes? Or every person for themselves?

10 Upvotes

38 comments sorted by

42

u/Rumborack17 Aug 25 '26

I mean how do you QA manual written SQL Queries/objects? And why do you need a different process for AI written ones?

17

u/IndependentTrouble62 Aug 25 '26 edited Aug 25 '26

The issue is the volume of code a Jr with claude code can generate. In most places I have worked the teams on are not large enough to QA that volume. I generally agree with your sentiment but AL tools will can completely overwhelm a small teams ability to manage the volume.

3

u/Extreme-Soil-3800 Aug 25 '26

Agreed on volume. The SQL code is also not going through any manual review processes / is challenging to ensure AI-generated SQL flows through my team.

8

u/Signal_Till_933 Aug 26 '26

We have a junior who puts up fucking massive PRs with the most verbose fucking descriptions you could imagine.

I ask him to explain even parts of the description and he has no idea. Like "Your description says xyz but I can't find it cause your code has thousands of lines. Where is it" and he has no idea 😂

13

u/jackalsnacks Aug 25 '26

And there lies the perpetual problem that we are all facing. Only solved by an engineering renaissance (in my opinion) where real engineers with real experience will need to refactor all the slop being produced. AI was a great disrupter And money sink.

My general advice for my peers and engineers is to keep learning architecture and prepare for the renaissance and, just like most great disrupters, the pendulum will swing once again and opportunity will return. It feels like doom and gloom now.

5

u/IHoppo Aug 25 '26

Yeah. I've retired - if my money is looking a bit low in 5 years time I'll expect to come back and do some dull, well paid, refactoring work. No-one with career aspirations will want to do that, it'll be Cobol-Y2K all over again.

3

u/feudalle Aug 26 '26

I miss the y2k days sometimes.

3

u/TempMobileD Aug 25 '26

I’m seeing people completely bypass the thoroughly vetted pipeline and asking Claude (via an MCP) questions like “how does X look since last month” which generates queries analysts have no way to really look at, except for a constant torrent of AI generated queries visible on the computer cluster.
It is terrifying.

11

u/mikethomas4th Aug 25 '26

Read it?

AI isn't inventing a new language, its coding in SQL. Just read it and see what its doing. This is an odd question.

3

u/Extreme-Soil-3800 Aug 25 '26

So you have a process where every agent at the company passes the SQL to the data team so they can read it? Or do you audit?

The question isn’t whether or not it’s SQL, the question is how do you insert into an otherwise closed loop process of ask agent question > run query > present as fact

5

u/Signal_Till_933 Aug 26 '26

Are you asking how to prevent people from running AI generated SQL? Because the answer is the same as before AI: don't let people who don't know what they're doing run queries.

Whether that is a problem for you to solve or leadership to solve is debatable.

9

u/fauxmosexual NOLOCK is the secret magic go-faster command Aug 25 '26

I think you're asking the wrong question: your agents should be querying semantic models, really the only way to solve this is to make sure the agent is using a nearly bulletproof model with fixed definitions and measures, and doing iterative improvements as you check what is/isn't working and build out libraries of skills or a knowledge base for the agent to use. Getting it to do raw SQL to run without QA is not going to be reliable.

16

u/Thefuzy Aug 25 '26

SQL QA has been a joke long before AI

6

u/Signal_Till_933 Aug 26 '26

As an analyst I agree. Half my job is just getting "its slow when loading this data" tickets, finding the query, and submitting it as a performance bug.

If I'm feeling nice that day I'll submit execution plans and suggested fixes as well.

6

u/Large_Hedgehog2416 Aug 25 '26

Create a code review skill

Have your coding standards as steering files

Use your code-review skill to review the code against your coding standards?

3

u/Upper-Raspberry4153 Aug 25 '26

What do you mean, I just put ‘don’t mess up’ at the end of all my prompts.

2

u/decrementsf Aug 25 '26

Along side new tools drill fundamentals the slow boring way enough to also build intuition for QA. We are all supervisors and perform technical review now.

2

u/shougaze Aug 25 '26

It’s sql

2

u/vintagegeek Aug 25 '26

I know my data, and I usually know when something is off. I never ask for UPDATE or DELETE queries from Claude EVER. Display only, and then I check what's being displayed for accuracy. Never take it at face value.

2

u/reditandfirgetit Aug 25 '26

I went throught this about 2 months ago. New agent, customer facing. For ours, the dev created an MCP that uses existing APIs and is narrowly focused to a specific set of tools

2

u/ArielCoding Aug 25 '26

Layer it: automated checks block for obviously dangerous stuff (like a DELETE with no WHERE clause) before it can run, then test on staging copy, and a human reviews anything that changes data.

3

u/az987654 Aug 25 '26 edited Aug 25 '26

Evaluate the output, is it what you expect?

You know, do your job the same way you did before you had AI write a query.

1

u/kiwi_bob_1234 Aug 25 '26

Keep code changes small like you would with a normal PR

1

u/Prestigious_Bench_96 Aug 25 '26

(Depressingly?) domain knowledge has become the primary safeguard - given the failure modes of agents they are reasonably good at ironing out inconsistencies and syntax issues; so - an analysis that spans multiple queries is usually off more in a fundamental miss on data source, business context, etc. 

You can make this more systemic with some reference outputs to benchmark queries against.

1

u/konoo Aug 25 '26

Easy ask the AI to do it!

lol is joke...

1

u/MatsuDano Aug 25 '26

At my current employer, the way is to restrict who has access to agents and restrict even further who can submit merge requests.

A tool is only as good as its wielder. People should not be presenting as fact information that they cannot understand.

1

u/aardw0lf11 Aug 25 '26

Check the results it gives you without using AI assistance. If something in the results doesn’t look right then it probably isn’t. Being able to recognize that when it happens (because it WILL) is going to be an important skill to have for the foreseeable future.

1

u/Fine-Ad-1732 Aug 26 '26

Ja fiz alguns exercícios onde após terminar minhas analises pedi p o Claude fazer a analise por ele, brifando o que eu queria, e ele consegue ser mais amplo e pensar em coisas que eu não falaria ali mas porque eu teria o contexto que ele não tinha, mas foi boa a experiencia porque os mesmos valores que eu calculei no meu exercício ele também apresentou, então minha experiencia tem sido boa porem tem que conferir o que ele faz eu também ja vi ele errar.

1

u/groversnoopyfozzie Aug 26 '26

Ever heard the phrase,” Can’t see the Forrest for the trees?” I find that using AI to thin the trees helps to comprehend and edit the rest of the project.

1

u/mschmitt1217 Aug 26 '26

More of a data governance issue than anything else. These type of questions should have been answered upfront and only "certified" datasets used in analysis. If the data is clean, then you would be having the same exact issues if they didn't use AI and just created their own queries.

1

u/ProfessionalDirt3154 Aug 26 '26

An agent is - mutatis mutandis - same as a junior to mid dev. What do you expect when you ask the same question of one of the humans? You should expect ~same from the AI. Or, if you're letting junior/mid manage junior/mid you have problem analogous to A people hire A people, B people hire C people. And if you're allowing someone to do stuff they can't explain, no matter how they did it, that's another different problem again.

1

u/HercHuntsdirty Aug 26 '26
  1. Run query locally and validate
  2. Run query in demo env and give customer access
  3. Customer signs off on changes
  4. Run update on production

1

u/theseyeahthese #TempTables ally Aug 25 '26

AI is pretty good at accelerating QA as well. The trick is to not just ask “does this query look right”, you have to come up with the conceptual test cases that you want to verify given your knowledge of the requirements. Then, explain those requirements, test cases, and schema to the AI, and it can help you very quickly generate relevant test data as insert statements, as well as the expected result given that test data + the requirements. Run the test data insert statements, run the actual query against it, and compare the actual query result vs the expected result.

As long as you specify the requirements yourself and don’t provide it with the actual query ahead of time, it can’t “cheat” by using the actual query as the source of truth.

Once you get into a groove as to how to do this, you can find ways depending on your sql software and your team’s workflow to build a “library” of these QA checks for regression testing, and then ultimately automate the running of them on some schedule if you wanted.

0

u/murdercat42069 Aug 25 '26

Here's the fun thing, they aren't!

-1

u/FinickySerenity Aug 26 '26

Claude can run an explain query and analyze the results. This is not a serious question.

5

u/Extreme-Soil-3800 Aug 26 '26

Who is evaluating the results of the explain plan for accuracy? Claude? This is not a serious answer.