DEV Community

Cover image for DriftGuard — AI Code Sanitizer & Refactor Agent Powered by Sanity Context
Aksa Fatima
Aksa Fatima

Posted on

DriftGuard — AI Code Sanitizer & Refactor Agent Powered by Sanity Context

Sanity Challenge Path One Submission

This is a submission for the Sanity Challenge, Path One: Ship an Agent That Queries Real Content

What I Built

AI can generate code really fast.

But one problem I kept running into is that the code can look completely correct while still using an old API or outdated documentation.

That is why I built DriftGuard.

DriftGuard is an AI code auditing and refactoring agent. You give it code, and it checks that code against a structured knowledge base containing information about deprecated APIs, current versions, and their recommended replacements.

For example, if the code uses an outdated Next.js API, DriftGuard can identify the issue, explain what changed, and suggest the newer approach.

The main idea behind the project is simple:

Don't just ask an AI whether code is correct. Give it a source of truth to check against.


Demo

Here’s a short walkthrough of DriftGuard, showing how it checks code against the Sanity-powered knowledge base and identifies outdated APIs.

🎥 Demo: [https://youtu.be/3RvNo10mnC8?si=kXwCE2mkY0PN7O3m]

The demo shows the basic flow:

Code → Sanity Context → Code Rules → AI Audit → Identify outdated code → Refactor


Code

💻 GitHub Repository: [https://github.com/AKSA119/driftguard]


How I Used Sanity

This is where Sanity became an important part of the project.

Instead of keeping all the rules inside prompts or hardcoding them into the application, I created a Sanity project and modeled the coding rules as structured content.

I created a Code Rule document type with fields such as:

  • Technology
  • Version
  • Status
  • Old API / Code
  • Replacement
  • Explanation
  • Official Source URL
  • Last Verified

I added rules for things like:

  • Next.js 15 async request APIs
  • Vercel AI SDK 5 addToolResult → addToolOutput
  • Vercel AI SDK 6 generateObject deprecation

DriftGuard connects to the Sanity Context MCP endpoint from the backend and retrieves these rules from Sanity.

The retrieved content is then used alongside the user's code during the AI audit.

So instead of the model simply saying:

"I think this API is outdated."

it has structured information from Sanity that tells it what changed, which version it applies to, what the replacement is, and where the information came from.

That was the part of the project I found most interesting — Sanity isn't just storing content here. It is acting as the knowledge layer that the agent can actually query.


Sanity Project Details

Project ID: wam7t4lk

Dataset: production

The project contains the structured Code Rule documents used by DriftGuard.

This is also the project the Sanity team can inspect to see how I modeled the content behind the agent.


How the Agent Works

User Code
    ↓
DriftGuard
    ↓
Sanity Context MCP
    ↓
Code Rules from Sanity
    ↓
Relevant rules retrieved
    ↓
AI Code Audit
    ↓
Outdated / deprecated APIs identified
    ↓
Sanity-grounded refactoring
    ↓
Updated Code
Enter fullscreen mode Exit fullscreen mode

What I Learned

The biggest thing I learned while building DriftGuard is that connecting an AI model to real, structured information changes how useful the system can be.

Getting the first demo working was actually the easy part.

The harder part was dealing with things like MCP connections, authentication, outdated model versions, API changes, and making sure the AI output followed the format the application expected.

There were definitely a few moments where something that looked like a small change turned into a debugging session. 😅

But that was also the most useful part of the build.

DriftGuard started as an idea about detecting outdated code, but it ended up teaching me a lot about how AI agents, structured content, MCP, and real-world debugging fit together.

sanitychallenge #sanity #dev #webdev

Top comments (0)