How to Configure Vercel AI SDK DynamoDB Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a vercel ai sdk dynamodb audit log by linking model callbacks to table writes. Your app captures each prompt and response, then writes the event to a table. Many teams start by giving the app broad cloud permissions to write these records. When roles are too broad, a bad prompt or code bug can change or delete past logs. How a vercel ai sdk dynamodb audit log works The AI toolkit runs in your server code and sends requests to language models. It offers hooks that trigger when a mod

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a vercel ai sdk dynamodb audit log by linking model callbacks to table writes. Your app captures each prompt and response, then writes the event to a table. Many teams start by giving the app broad cloud permissions to write these records. When roles are too broad, a bad prompt or code bug can change or delete past logs.

How a vercel ai sdk dynamodb audit log works

The AI toolkit runs in your server code and sends requests to language models. It offers hooks that trigger when a model starts or finishes a reply. Your code uses these hooks to gather the prompt, the reply, and the token count. You also attach a timestamp and a user ID to each event record.

Next, the app uses a cloud role to log in with DynamoDB and write the item. Teams pick a partition key like user ID and a sort key like timestamp. This key layout lets security teams query events by user or by date range. A separate cloud trail can also record control plane changes to the table itself.

What the native setup solves and where it falls short

This native logging flow gives your team a fast place to store model history. It scales well when your app sends thousands of prompts each minute. You can also set a time-to-live rule so old records expire on schedule. Cloud roles decide which server functions can log in and write to the table.

Still, static cloud roles only check who logs in at the start of a session. They do not inspect what individual requests or database calls do in flight. If an app holds keys in memory, a leak exposes the whole table. Also, raw prompts often contain emails, phone numbers, card numbers, or national IDs.

Writing raw text straight to the database stores sensitive user data in your logs. Custom code to scrub these fields inside each app takes time to maintain. If one developer forgets a filter, private data lands in the table right away. You also lack a way to pause risky tool calls before they run.

AI Audit Trails + Audit Log Integrity: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to tighten permissions and scrub sensitive fields

Start by scoping the cloud role so the app can only add new items. Remove permissions that allow the app to update, delete, or scan existing table rows. Use a separate read-only role for auditors who need to review past records. This split stops a compromised app from wiping out its own audit trail.

You should also add a data masking step before the write happens. Masking rewrites matched fields like emails and card numbers in results and payloads. Centralizing this check keeps app code simple and applies the same rules everywhere. Finally, require human approval when an AI agent tries to run a risky command.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

What should we store in each AI audit record?

Store the user ID, timestamp, model name, token counts, and the masked prompt text. Include any tool call names and parameters so you can trace agent actions later.

How do we stop the app from deleting its own logs?

Give the app role permission to put items into DynamoDB, but deny delete actions. Store backups in a separate account with strict audit storage rules for extra safety.

How do we handle private data in user prompts?

Run a masking rule that rewrites emails, phone numbers, and card numbers before storage. This keeps your audit trail useful for debugging while reducing data exposure risks.

The query runs. The emails stay hidden.