Using the Airtable API from an AI Agent
Someone renames a field in the Airtable UI and your agent breaks with an error saying the field does not exist, while you are looking right at it. How Swytchcode keeps delete off the allowlist while that schema drifts.
Key takeaways
- -Deleting and recreating a field in Airtable keeps the same name but gets a new ID, so anything referencing the old ID breaks with an error that looks wrong even though the field is visibly still there.
- -Airtable allows only 5 requests/second per base, and exceeding it triggers a 30-second penalty, not a brief backoff, plus a separate monthly call cap by plan.
- -Airtable has no undo through the API, so leaving delete methods off the allowlist removes the single worst-case outcome regardless of how the schema drifts.
- -Swytchcode's allowlist covers schema reads, listing and batch updates while excluding delete, and a policy gates writes to tables that matter, like a finance master table.
- -Creating records is not idempotent and there's no unique constraint stopping a duplicate; an idempotency key plus an external-ID lookup before creating is the real fix.
Here is a bug report you will eventually receive. The agent stopped working. The error says the field does not exist. You open the base and the field is right there, with the same name it has always had. Nobody is lying. Someone on the ops team deleted that column and made a new one with the same name, type and position, because that felt like the tidy way to change its settings. To Airtable, that is a different field with a different ID, and anything holding the old ID now gets rejected with the API telling it the field is unknown.
Airtable is the friendliest database your non-technical colleagues have ever used, which is exactly why it is the least stable schema your agent will ever depend on. People change it, constantly, with no idea anything is reading it.
The general problem is that an agent has no way to tell the difference between a base that changed underneath it and a base that is just fine, unless it checks. Swytchcode's fix is less about the schema itself and more about making sure nothing the agent writes can do real damage while that schema is drifting out from under it.
The problem: the schema your agent depends on changes underneath it
You can reference a field two ways, and both break differently. By name, a reference survives a delete-and-recreate, because the new field has the same name, but breaks the moment someone renames "Status" to "Stage." By ID, a reference survives renames, which is the common case, but breaks on delete-and-recreate with a confusing error. For agents we lean towards IDs, because renames happen far more often than recreations, and a rename is completely invisible to everyone involved. Nobody thinks "I should tell the engineering team" when they tidy up a column header.
This is the Airtable-specific version of a general problem: a human reads the changelog, an agent keeps calling the old thing until it breaks. We wrote that up in API versioning strategy when AI agents are your consumers, and the tool-selection cousin of it is in why your AI agent calls the wrong API.
There is a second, sharper version of this problem: deletion. Airtable has no undo through the API, so a confused agent deleting records from a table your ops team depends on is a genuinely bad afternoon, and it does not require a schema change to happen, just one wrong tool call.
How Swytchcode solves it
Swytchcode downloads Airtable's catalog of methods and lets you turn on schema reads, list, and batch update, while leaving delete off the allowlist entirely. If the method is not added, there is no instruction, injected or direct, that can reach it, which removes the worst-case outcome regardless of how badly the schema has drifted.
Your token goes to a local store outside the project, encrypted at rest, and is injected at call time, so there is no credential for the model to read or a trace to leak. That is worth caring about specifically here, because an Airtable token often reaches a lot of operational data at once.
Setting up Airtable with Swytchcode
npx swytchcode
swy login
swy init --mode=sandbox
swy get airtable
swy auth connect airtable # personal access token or OAuth
swy auth status
# read the schema first; everything else depends on it
swy discover "get base schema" --project airtable
swy discover "list records" --project airtable
swy discover "update records" --project airtable
swy list methods airtable
swy info <canonical_id>
swy add method <canonical_id> # schema read, list, batch update. Not delete.Scope every discover with --project airtable, and run swy get before swy info. See the authentication docs and scope the token to the specific bases it needs.
import { exec } from "@swytchcode/runtime";
// 1. Read the schema ONCE per run and build the map.
const schema = await exec("<airtable get-schema canonical_id>", {
params: { baseId: BASE_ID }
});
const fields = Object.fromEntries(
schema.tables.find(t => t.name === "Orders").fields.map(f => [f.name, f.id])
);
// 2. Fail loudly if what you need is gone, instead of improvising.
for (const needed of ["Status", "Owner", "Notes"]) {
if (!fields[needed]) throw new Error(`Airtable field missing: ${needed}`);
}
// 3. Batch in tens, referencing by field ID.
for (const chunk of chunksOf(updates, 10)) {
await exec("<airtable update-records canonical_id>", {
params: { baseId: BASE_ID, tableId: TABLE_ID },
body: {
records: chunk.map(u => ({
id: u.recordId,
fields: { [fields.Status]: u.status }
})),
returnFieldsByFieldId: true
},
idempotencyKey: `orders-sync:${runId}:${chunk[0].recordId}`
});
}The pattern that matters: read the schema once per run and build a name-to-ID map, fail loudly if a needed field is missing instead of letting the agent improvise, and batch in tens, referencing fields by ID. The returnFieldsByFieldId flag is worth knowing too, since it makes responses use field IDs rather than names, so your parsing does not break on a rename either.
Policies: build agents you can trust with write access
In Airtable the useful rule is usually about which table, not which amount. Writing to a staging table is fine; writing to the table your finance team reports from is a different matter.
{
"id": "protect-the-master-table",
"target": ["<airtable update-records canonical_id>"],
"when": { "field": "tableId", "operator": "==", "value": "<finance-table-id>" },
"action": {
"type": "REQUIRES_APPROVAL",
"message": "Agent wants to write to the finance master table"
},
"approval_timeout": "4h"
}Add a second rule capping batch size so "clean up the statuses" cannot rewrite thousands of rows in one run. Held calls go to Slack or Telegram and fail closed. Schema in the policy reference, approval setup in the human approval docs, and the reasoning for keeping rules in git in policy-as-code for AI agents.
Airtable is the database your least technical colleagues edit directly, which is exactly what makes its schema unstable under an agent that assumes field names or IDs stay put. The problem is that a rename or a delete-and-recreate is invisible to everyone except the agent that breaks because of it. Swytchcode solves it by leaving delete off the allowlist entirely and gating writes to the tables that matter behind a policy, so a schema that drifted underneath the agent produces a loud, caught error rather than a quiet, expensive one.
Related reading
- Airtable integration page
- Connecting Notion to an AI Agent
- Can AI Do API Testing? What Works and What Doesn't
- API Observability for AI Agents
- Browse all 300+ API integrations
Things we got wrong
We hardcoded field names, because it was quicker and the names looked permanent. Three weeks later someone renamed two columns while tidying a view, and the agent started writing to nothing in particular. We also treated the rate-limit error like a normal one and retried after a second, which, given a thirty-second penalty, meant every retry failed too and looked like a much bigger outage than it was. And we tested on a Free workspace and ran out of monthly calls on a Tuesday, which presents as a rate-limit error that backoff cannot solve. Check your actual call volume with the audit log before you blame the code.
FAQ
Field IDs or field names for an agent?
IDs, resolved at runtime from the schema rather than hardcoded, with a validation step that fails loudly when something is missing. That survives renames, which are common, and turns recreations into a clear error rather than silent misbehaviour.
Why did I get an unknown-field error for a field I can see right in front of me?
Someone deleted and recreated it, so the name is the same and the ID is not, and the API returns a 422 UNKNOWN_FIELD_NAME. Re-read the schema, update whatever cached the old ID, and ask your base owners to change field settings in place in future, which is Airtable's own guidance for preserving the ID.
What are the actual rate limits and call caps I should plan for?
Airtable allows 5 requests per second per base, and exceeding it gets you a 429 followed by a 30-second penalty before requests succeed again, not a brief backoff. A single request can trigger it if it arrives just after someone else's burst against the same base, since the limit is per base and your agent is probably not the only thing talking to it. Separately, there is a monthly call allowance tied to your plan: 1,000 calls a month on Free, 100,000 on Team, unlimited on Business and Enterprise, and blowing through it returns 429 PUBLIC_API_BILLING_LIMIT_EXCEEDED, which does not reset until the first of the next month. Batch create and batch update take up to 10 records per request, so a 100-record update is 10 calls rather than 100, which is the real fix for the per-second limit; oversized payloads return 413 Request Entity Too Large. One Airtable tip worth knowing: the monthly allowance follows the workspace the base lives in, so moving a base into a higher-paid workspace raises its ceiling.
Is Airtable a sensible system of record for agent work?
For coordination and ops, absolutely, and the fact that humans can edit it is the feature. For anything where correctness is critical and schema stability matters, treat it as a view onto a real database rather than the source of truth. The Notion guide makes a similar point about databases there.
Can I build an AI agent on top of Airtable with Swytchcode?
Yes. The catalog and allowlist let you turn on schema reads, listing, and batch updates, while a policy on batch size and the per-request limit of 10 records give you two natural brakes against an oversized rewrite.
Can Swytchcode stop an agent from deleting records, even if it's asked to?
Yes. Leaving the delete methods out of the allowlist removes the capability entirely, so no instruction, injected or direct, can reach it, and since Airtable has no undo through the API, that is the one method worth being strict about above all others. swy audit policy shows you what it tried to do and was stopped from doing, which is usually an education about your own prompts. More in API access control for AI agents.
If an agent retries a create-records call after a timeout, will Swytchcode let it duplicate the rows?
Not unprotected. Creating records is not idempotent, and Airtable rows are easy to duplicate because there is usually no unique constraint stopping you: the request lands, records are created, the response is lost, the agent retries, and now your ops team has two of everything. Writes are only auto-retried when an idempotency key is set, so an unprotected batch create fails visibly rather than silently doubling. Derive the key from the source record and the run, and since there is no database constraint to save you, add a cheap guard: keep an external ID column and look up before you create. Background in API idempotency: the complete guide and mechanics in the idempotency docs.
More content
API Governance Tools That Block a Pull Request When a Policy Check Fails
Spectral, Redocly CLI, and vacuum all fail a PR's CI check when an OpenAPI spec breaks a governance rule. How the gate is actually wired up, and why it's a different layer from Swytchcode's own runtime policy checks.
API Governance Tools With a Free Tier: What Small Teams Can Actually Use
Most API governance comparisons assume an enterprise budget. Here's what's genuinely free with no catch, what's gated behind a paid plan, and the realistic free stack a small team can actually run.
API Spend Caps for AI Agents: Capping Cost Before the Invoice Does
Most teams find out an agent overspent on a metered API when the invoice arrives. An argument-level policy that caps the metric a provider actually bills on, checked before the call goes out, catches it in the moment instead.
