Secure input validation for Google Antigravity IDE
# Input Validation Guide for Google Antigravity
Master input validation in Google Antigravity IDE.
## Schema Validation with Zod
```typescript
import { z } from "zod";
const userSchema = z.object({
email: z.string().email("Invalid email format"),
password: z.string().min(8, "Password must be at least 8 characters"),
name: z.string().min(2).max(100),
role: z.enum(["user", "admin"]).default("user")
});
type UserInput = z.infer<typeof userSchema>;
export function validateUser(input: unknown): UserInput {
return userSchema.parse(input);
}
```
## API Route Validation
```typescript
import { NextRequest, NextResponse } from "next/server";
const createPostSchema = z.object({
title: z.string().min(1).max(200),
content: z.string().min(10).max(10000)
});
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const validated = createPostSchema.parse(body);
const post = await db.post.create({ data: validated });
return NextResponse.json(post, { status: 201 });
} catch (error) {
if (error instanceof z.ZodError) {
return NextResponse.json(
{ error: "Validation failed", details: error.flatten() },
{ status: 400 }
);
}
throw error;
}
}
```
## Best Practices
1. **Validate at boundaries**
2. **Use type-safe schemas**
Google Antigravity IDE provides validation scaffolding.This Validation prompt is ideal for developers working on:
By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their validation implementations.
Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.
This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.
You can modify the prompt by adding specific requirements, constraints, or preferences. For Validation projects, consider mentioning your framework version, coding style, and any specific libraries you're using.