The Test is Green, But the DB is Empty: Testing AI Agents on AWS

The Test is Green, But the DB is Empty: Testing AI Agents on AWS

Traditional pass/fail test scripts break the moment software starts reasoning and calling tools on its own. Here is my practical, battle-tested blueprint for testing and governing agentic AI systems without losing your sanity.

For years, my job as a QA analyst was beautifully predictable. You gave the system input X, and you asserted that it produced output Y. If the API returned  200 OK , the SQL row updated correctly, and the Playwright script found the confirmation button, we shipped it.
We had rules. We had order.
Then along came agentic AI, and suddenly, the software started winging it.
Unlike standard chatbots that just generate text, "agents" actually do things. They read user prompts, decide what tools or APIs to use, change database states, and call external services—all on the fly. You can run the exact same prompt twice, and the AI might take two completely different paths to get to the answer.
When your code starts deciding its own workflow, the traditional "expected vs. actual" test script breaks down entirely. In fact, one of the most frustrating failures I’ve seen is when the UI asserts "Successfully updated!" with a polite little AI checkmark, but you look under the hood and realize the backend tool call failed silently, and the database is completely empty. The test looked green, but the application was broken.
Between my day job in enterprise QA and my evenings teaching Python and computing to university students, I see a lot of people trying to build with AI. The biggest headache isn’t getting the agent to talk—it’s proving that the agent is actually doing what it was told to do, and only what it was told to do.
Here is my practical, hands-on blueprint for testing and governing AI agents on AWS without losing your mind to non-deterministic chaos.



The AI Agent’s "Favorite" Ways to Break

Before diving into tools, we have to look at how these systems actually fail in real life:
  • Sincere-sounding failures: The agent is extremely polite. It tells the user, "I've processed your refund!", but the underlying API failed or passed the wrong parameter. The user is happy; the backend didn't do a thing.
  • Trajectory drift: The agent eventually gets to the right answer, but it takes an absurd, circular route to get there. It calls three unnecessary APIs, runs up your token costs, and makes the user wait 15 seconds.
  • The "curious" agent: Without strict boundaries, an agent can get creative. If it has access to databases or file directories, prompt injection or simply weird reasoning can lead it to access things it shouldn't.
  • Pipeline-ruining flakiness: Asserting on exact natural-language responses is a nightmare. If the agent changes "Sure thing!" to "Certainly!" in a UI update, your E2E pipeline goes red for absolutely no reason.
To test this, we can’t just rely on standard UI test runs. We have to treat QA like building a sandbox.



The 4-Layer Testing Playbook

You can't predict what an AI will say, but you can control and validate what it is allowed to touch. Here is how I approach this on AWS.

1. Hardguard Your Tool Layer (Keep Your API & DB Boring)

Just because the agent gets to choose which tool to call doesn't mean the tool itself gets to be unpredictable.
The most important rule I can share: The agent is smart, but your API should still be a brick wall.
  • Strict Contracts: Put OpenAPI and JSON schemas on every single endpoint, Lambda function, or tool your agent can invoke. If the agent tries to pass a hallucinated ID or malformed payload, make the schema validation fail instantly. Don't let bad input travel downstream.
  • Don't Trust the Output: Write automated tests that verify the state, not just the string. If your agent is supposed to update a status, have your pipeline query the SQL database directly to verify the change happened.

2. Know When to Use Playwright vs. Testing the Agent's Logic

I get asked a lot if E2E frameworks like Playwright are obsolete now that we have agentic testing. The short answer: absolutely not. You just need to split the work:
  • Keep your core stuff deterministic: Logging in, payment flows, billing, and basic navigation do not need AI. Use Playwright (I prefer C#/.NET) for these. They should run fast, repeat exactly, and remain cheap.
  • Use "Trajectory" testing for the agent: On the AI side, stop asserting on exact words. Start testing "trajectories." Your tests should evaluate: Did the agent call the correct sequence of tools? Did it resolve the task within a reasonable number of steps? Did it run without triggering security blocks?
  • Keep an eye on tools like Amazon Nova Act to help automate complex, highly dynamic user paths where traditional, hardcoded selectors would simply crumble.

3. Build a Proper Sandbox Before Production

Security isn’t something you handle with prompts like "Please do not delete anything." Believe me, users (and AI) will find a way.
When you build with Strands Agents or run them through Amazon Bedrock AgentCore, make isolation part of your local testing checklist:
  • Policy Enforcement: Test your agent against microVMs and local environments like Strands Box on AgentCore to observe how it interacts with systems. Can you trick it into accessing unauthorized files? Put your security policies in the infrastructure, not the system prompt.
  • Gated Actions: Any high-stakes action—like changing user roles, processing refunds, or deleting data—must have a hard "human-in-the-loop" approval gate. Write tests to confirm the system actually pauses and waits for confirmation rather than auto-piloting through it.

4. Live Observability Is Actually Continuous QA

In traditional software, you can write enough test cases to cover most paths. With an agent, you can’t predict every prompt a human will write. That means production tracing is the final test suite.
We monitor four specific things using Amazon CloudWatch:
  • Schema Errors: How often are backend tools rejecting the agent's input?
  • Action Loops: Is the agent getting stuck in loop trajectories and inflating latency?
  • Policy Blocks: Did the system deny a tool call because the agent tried to overreach its permission?
  • Latency/Costs: Are runs getting slow or wildly expensive?
If an agent behaves badly in production, we catch that trace, analyze the failure, and turn that user's interaction into a new test case back in our staging pipeline.



A Quick Cheat Sheet for Pre-Release

Before pushing an AI agent live, run this five-point check:
  • [ ] Contract Verification: Are all endpoints backed by strict input validation that fails immediately on bad data?
  • [ ] State check: Do your tests assert on database and API changes, or are they just validating the AI's polite message?
  • [ ] Sandboxing: Are your files, networks, and MCP tools isolated at the runtime level? Or are you just hoping the system prompt works?
  • [ ] Trajectory control: Is there a maximum step count and timeout to stop the agent from looping and costing you a fortune?
  • [ ] Gating: Are human approvals explicitly required and verified for high-impact mutations?



Wrapping Up

Agentic AI doesn’t make quality engineers obsolete; it actually makes our jobs more important. Our focus has to shift from manually clicking through scripts to building the guardrails and automated sandboxes that make autonomy safe.
Are you testing AI workflows, or just letting them run in the wild and hoping for the best? Let's talk about the craziest AI edge-case or silent failure you've caught in the comments.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article