Sub topic 10
Reviewing and correcting generated output
This chapter assumes you have read the chapters on data modeling and prompting an AI app builder. You should have a tasks-style data model with an owner field, and a first app generated from a structured prompt. Here you learn how to check that app and fix what is wrong without breaking what works.
Why generated apps need review
An AI app builder produces an app that looks finished. Screens render, buttons respond, and sample data appears. That does not show the app is correct. The builder optimizes for a plausible result, so it often does these things:
- Builds extra features you put out of scope.
- Skips rules you stated once and never repeated.
- Uses open access rules because they make the demo work.
- Hard-codes values such as a test user, a price, or an API key.
You are the reviewer. Your job is to compare the app against your own prompt, not against how it looks.
A review order that catches the expensive problems first
Check things in the order of how costly they are to fix later. Data and access problems are costly because they affect every screen built on top of them.
1. Scope against the core flow
Walk the core flow as a new user: sign up, create a task, see only your tasks, mark one done. Then list every screen and feature that exists. Anything outside the flow, such as a team page or a notifications settings screen, is scope creep. Remove it or ignore it. Unused features still carry bugs and data, and they confuse testers.
2. The data model
Open the builder's database view and compare it with the model you specified. Look for:
- Missing fields, or renamed ones (
clientinstead ofclient_name). - Wrong types, such as a due date stored as free text.
- Missing constraints.
statusshould accept onlytodo,doingordone. - No
owner_id, or anowner_idthat is not tied to the signed-in user.
Fix the model before touching the screens. Changing a field later means rewriting every screen and workflow that uses it.
3. Access rules
This is the check that matters most. A generated app often hides other people's data in the interface only. The data is still readable by anyone who calls the backend directly.
If your backend is Postgres, such as Supabase, list the tables that have no row-level security:
select c.relname as table_name
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public'
and c.relkind = 'r'
and not c.relrowsecurity;Then read the policies that exist:
select tablename, policyname, cmd, qual, with_check
from pg_policies
where schemaname = 'public';A policy whose qual is true lets every signed-in user, and sometimes anonymous users, read every row. The correct form ties each row to the user, as in auth.uid() = owner_id.
Then test it with two accounts:
- Create account A and add a task.
- Sign in as account B and confirm the task is not listed.
- While signed in as B, try to open A's task by pasting its URL or id. It should return nothing or an error.
If B can see A's task by URL, the rule is enforced only in the interface.
4. Secrets and where logic runs
Search the generated code or settings for keys, tokens and prices.
- Secret keys (payment secret keys, service-role keys, AI provider keys) must never appear in code that runs in the browser. Anything shipped to the browser is visible to every visitor.
- Public keys, such as a payment publishable key, may be in the browser.
- Rules that decide money, permissions or limits must run on the server. A discount calculated in the browser can be changed by the user.
If you find a secret in client code, rotate it first. Then move the logic server-side. Deleting it from the code is not enough, because the old key may already be exposed.
5. Edge cases and states
Generated apps usually handle the happy path only. Try these deliberately:
- A new account with no data: is there an empty state, or a blank page?
- An empty title, a very long title, or a due date in the past.
- A failed request, for example by going offline mid-save.
- Double-clicking the submit button.
- Signing out and pressing the browser's back button.
Correcting without breaking things
Fix one problem per prompt, and name the exact object and the expected behavior. Vague requests such as "make it more secure" lead the builder to rewrite large parts of the app.
Problem: any signed-in user can read other users' tasks by requesting the task id.
Change only: the tasks table access rules.
Expected: select, insert, update and delete are allowed only when owner_id equals the signed-in user's id.
Do not change: screens, field names, or the status values.
After the change, tell me which policies you created.After each fix, rerun the check that failed and one earlier check. Builders sometimes fix one thing and undo another. Keep a short log: what you found, the prompt you sent, and the result. If the builder has version history, create a restore point before each fix.
If the same problem survives two or three prompts, stop prompting. Edit the setting by hand in the database or permissions screen, or use a different approach. Repeated prompts on a stuck issue tend to add layers of workarounds.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Every user sees all tasks | Policy uses `true`, or row security is off | Add an owner-based policy and enable row security |
| Fields differ from your spec | Builder renamed them silently | Rename them to match and update dependent screens |
| API key visible in browser tools | Logic placed client-side | Rotate the key, move the call to a server function |
| Fix prompt changed unrelated screens | Request was too broad | Restore the saved version and repeat with a "do not change" line |
| Works for you, fails for testers | Only tested with your admin account | Test with a fresh account |
Exercise
You test your generated app with two accounts. Account B cannot see account A's tasks in the list, but pasting A's task URL while signed in as B shows the task. What is wrong, and what should your fix prompt specify?
Show answer
The access rule is enforced only in the interface (the list is filtered) and not on the data. The fix prompt should target only the tasks table's access rules, require that read, insert, update and delete are allowed only when owner_id equals the signed-in user's id, and say not to change screens or field names. Afterward, repeat the two-account URL test.
Exercise
While reviewing, you find a payment provider's secret key in code that runs in the browser. Give the first two actions in order.
Show answer
First, rotate (revoke and reissue) the key, because it may already be exposed. Second, move the logic that uses the key to a server-side function and keep only the public key in the browser. Deleting the key from the code alone does not secure it.