Hey everyone! Over the past few weeks, I've been working on a problem I kept running into while building mobile AI features: how do you let an LLM call native mobile tools (payments, calendar, BLE, external APIs) without risking a hallucination, prompt injection, or infinite loop wiping out user data or spamming APIs?
Most agent guardrails are built for Python backends, leaving the mobile client completely exposed. So I built react-native-agent-guard—a zero-trust tool governance and biometric gating layer for React Native & Expo.
We just shipped v0.3.2 (now at 93%+ test coverage) and added a live interactive Expo Snack playground so you can test the approval sheets, rate limiter, and PII redaction right in your browser without installing anything.
🚀 Try the Live Interactive Demo
Expo Snack Playground (Run in Browser or Expo Go): [https://snack.expo.dev/@git/github.com/Hassaan68/react-native-agent-guard:examples/expo-snack](https://snack.expo.dev/@git/github.com/Hassaan68/react-native-agent-guard:examples/expo-snack)
GitHub Repository:https://github.com/Hassaan68/react-native-agent-guard
What it handles out of the box:
Dynamic Policy Gating (auto | confirm | biometric | deny): Auto-approve low-risk reads, trigger a customizable native bottom sheet (AgentApprovalSheet) for state changes, or require hardware FaceID/TouchID (expo-local-authentication) for high-stakes actions—evaluated dynamically at runtime based on the LLM's arguments (e.g., < $50 = auto, $50–$199 = confirm, $200+ = biometric).
Vercel AI SDK & LangChain.js Adapters: Drop-in toVercelAITools() and toLangChainTools() wrappers that route your existing agent tool calls directly through the guardrail engine.
Agent Loop Protection & Rate Limiting: Prevents rogue LLM infinite loops from draining budgets with maxCallsPerMinute and maxSessionCalls—automatically blocking or escalating a tool's policy from auto to confirm/biometric when spammed.
Automatic PII Redaction & Audit Telemetry: Masks credit cards, emails, phone numbers, SSNs, and JWTs before emitting structured telemetry to onAudit or persistent storage (redactPII: true).
Remote MCP SSE Transport: Connect directly to Model Context Protocol (MCP) servers over SSE and automatically wrap discovered remote tools in local device policies.
Actionable llmFeedback on Errors: If Zod validation (.transform() / .refine()) fails, a rate limit hits, or a user denies a prompt, it returns structured feedback telling the LLM why it failed so it can self-correct instead of crashing the loop.
Quick Code Example:
TypeScript
import { createGuardrails, toVercelAITools } from 'react-native-agent-guard';
import { z } from 'zod';
const guard = createGuardrails({
rateLimit: { maxCallsPerMinute: 10, onLimitExceeded: 'confirm' },
redactPII: true,
});
guard.registerTool({
name: 'send_wire_transfer',
description: 'Send money to a recipient',
schema: z.object({
recipientEmail: z.string().email(),
cardNumber: z.string(), // Auto-redacted in audit logs!
amount: z.number().positive(),
}),
// Auto-approve under $50, confirm sheet $50-$199, FaceID/TouchID for $200+
policy: (args) => {
if (args.amount >= 200) return 'biometric';
if (args.amount >= 50) return 'confirm';
return 'auto';
},
handler: async ({ recipientEmail, amount }) => {
return await processPayment(recipientEmail, amount);
},
});
// Plug directly into Vercel AI SDK generateText / streamText
const tools = toVercelAITools(guard);
Links:
Would love any feedback on the API design, the Snack playground, or edge cases you're running into with mobile AI agents!