Ivan Jovanovic

Part 2 of 2 ยท knav write

Letting AI agents change a live Knack app safely

knav write is the companion to knav read (Part 1) that lets AI agents make changes to a live Knack app's schema and records. Relying on prompt instructions and scripts alone led to a real mistake where an agent deleted 48 live records. Built solo with AI agents, I turned the lessons from that incident into knav write, a 58-tool MCP server and CLI with 40 safety guards, dry runs, browser-only human approvals, and undo.

What can and can't be reverted

Once agents could read an app reliably, the next step was letting them make changes. Knack does not offer full flexibility to bring back app schema or data from a backup. To use agents for real build work on a Knack app, I had to consider the consequences of unintended changes.

The good news: app schema changes to the front end (pages, tables, forms, etc.) can be very easily reverted.

Initially I started with only allowing the agent to make changes to the front end. I created skills that instructed the agent to take backups of the full app JSON before changes so that if something went wrong I knew I had a fully accurate snapshot in time of the app schema that I could use to rebuild things easily and quickly. Because the JSON contains the full front end schema, nothing would be lost. This worked very well.

The bad news: app schema changes to the backend (fields, connections, records) cannot be easily reverted.

For example, if you delete a field, all data in that field for all records is gone. If you don't have a full backup of all records in that table, your data is gone and you have to ask Knack support to do a FULL app revert at whatever point in time their last backup was taken.

Because of this, I instructed my agents to start slow. Only add new fields, tables and records and do not modify or delete any existing fields or tables. After changes, use knav read to verify the app JSON was correctly modified. This worked well.

The 48-record delete

However, once it came to modifying existing fields, tables, and records, it became more complicated. On a client's app, I asked an agent to delete two test records that were no longer needed. The agent wrote a single script to query the records and delete the matches in the same run. The script filtered the table using a connection field that lived on another table. Knack's API ignored the filter without an error and returned the 50 most recent records instead. Because the lookup and the delete ran together in one script, the delete ran before the agent checked whether the filter worked. It deleted all 50 records (the 2 test records and 48 real ones) before realizing what happened and telling me. I rebuilt 29 of the 48 records with their parent links from an earlier export and the client's input, and the client chose not to restore the other 19.

What I changed in my workflow

This was a painful lesson. Due to this, I modified several parts of my agent skills and workflows:

  1. Back up both sides first. The agent must take a full backup of the records being changed and any parent records connected to them (because deleting a record in Knack also strips the link on the parent record, and Knack's CSV restore does not bring connections back).
  2. Never query and change in the same run. The agent is no longer permitted to query and modify (or delete) field or record data in a single script.
  3. Confirm every step:
    • Submit the query with the desired filters, read back the data, and confirm the filter field belongs to that table and the returned records are the exact ones I want.
    • Log the record IDs and expected count, and stop for my approval before changing anything.
    • In a separate run, perform the changes one record at a time using only the unique record ID.
    • Read back each record by ID after the change and compare the table's total count before and after to confirm the action completed as expected.
    • In case of any mismatch or issue, stop and inform me immediately.

To make sure the agent could not skip those steps, I also had it build a dedicated two-run delete CLI (safe-delete-records.js): the first run (plan) is read-only, takes explicit record IDs only, backs up the records and parent links, and prints a plan hash that I have to pass into the second run (delete --approve <hash>) before anything is deleted.

How knav write enforces the rules in code

With the knowledge gained from building the Knavigator web app, knav read, and these safety workflows, I built knav write with two important differences in mind:

  • knav write requires the app's API key to make changes to the schema and read/write records.
  • Making changes to the schema or records has much more drastic consequences if something goes wrong, so the safety rules had to be built into the tool itself.

How knav write enforces those rules:

  • The API key stays on my machine. The local @avvera/knav-write program holds the Knack API key and sends the requests directly to Knack. The key never goes to the hosted knav server and never enters the AI model's context.
  • Dry runs, impact checks, and backups before writes. When the agent calls a write tool, the server compiles the change, checks 40 safety guards and downstream impact across the schema, and saves a restore point before anything runs.
  • Human approval as an option. Each connected app has toggles in the dashboard for what requires approval before running: deletes, custom code, scheduled tasks, or all changes (all turned on by default for a live app, and optional when working on a test app). When a toggle is on, the change pauses for approval in the signed-in browser dashboard. An agent with terminal access could approve a command-line prompt on its own, so the approval gate lives in the browser where the agent cannot reach it.
  • Independent verification and undo. Knack's API can return success: true even when a setting was ignored. After every write, knav write re-reads the app to verify the change took effect, supports knavw_undo to revert the last change, and only charges a credit when the effect is verified.
  • Deletes by ID list only, and validated filters. To make the 48-record incident impossible in knav write, knavw_delete_records only accepts an explicit list of record IDs and never a filter query. On knavw_find_records, the server checks that every filter field belongs to that table before calling Knack (and after an early user hit a misnamed filter argument, every knavw_* tool also refuses unknown arguments outright instead of ignoring them).

Results

  • 58 MCP/CLI tools and 40 safety guards shipped publicly to npm as @avvera/knav-write on October 22, 2026, backed by 163 write test files (722 root tests and 594 program test cases).
  • Zero unverified writes since launch. Every schema and record change now runs through pre-write backups and post-write verification. On a real app, agents completed an app cleanup with 99 logged schema changes (shrinking the app by about 20%) without a single data loss incident.

What I learned

  • Start slow.
  • Let the agent do low-risk tasks and verify their outputs every time. This builds up their skillset and process.
  • Do not let the agent batch irreversible steps into a single run. Combining a lookup and a delete before verifying each step's output leads to issues that are not worth the increase in speed.
  • Prompt instructions alone are not enough for high-risk actions, because an agent can still misread a rule or skip a step. When something goes wrong, the real fix is to build the safeguard into the tool itself so the agent cannot make the same mistake again.

Links

← All writing