Library

Data Validation & Wrangling

LLMs return messy data. Validate it, transform it, and get type-safe results without wrestling with edge cases.

The Challenge

LLM outputs are unpredictable. You ask for JSON, you get JSON with extra text. You ask for a number, you get a number in quotes. You ask for a date, you get it in three different formats. Your agents spend more time parsing and validating than doing actual work.

Traditional validation libraries weren't built for AI. They throw hard errors on malformed input instead of trying to fix it. They don't understand that "5" and 5 should be the same thing when it comes from an LLM.

The FireFoundry Way

FireFoundry's data validation is designed for AI agents. It tries to understand what the LLM meant, not just what it literally returned. Coerce strings to numbers. Parse dates in any reasonable format. Extract JSON from markdown code blocks. Clean up the mess so your agent code stays clean.

Validate LLM outputs with schemas:
import { validate, z } from '@firefoundry/agent-sdk';

// Define your expected shape
const OrderSchema = z.object({
  orderId: z.string(),
  quantity: z.number().coerce(),  // Handles "5" → 5
  priority: z.enum(['low', 'medium', 'high']),
  requestedDate: z.date().coerce() // Handles multiple formats
});

// LLM returns messy data
const llmOutput = `Here's the order:
\`\`\`json
{"orderId": "ORD-123", "quantity": "5", "priority": "high", "requestedDate": "Jan 15, 2026"}
\`\`\``;

// We extract and validate it cleanly
const order = validate(llmOutput, OrderSchema);
// → { orderId: "ORD-123", quantity: 5, priority: "high", requestedDate: Date }
Built-in transformers for common patterns:
import { extractJson, extractList, extractCode } from '@firefoundry/agent-sdk';

// Extract JSON from LLM response that includes explanation text
const data = extractJson(llmResponse);

// Extract bullet points as an array
const items = extractList(llmResponse);

// Extract code blocks by language
const pythonCode = extractCode(llmResponse, 'python');

// Chain transformations
const result = pipe(
  llmResponse,
  extractJson,
  validate(OrderSchema),
  enrichWithDefaults
);

Zod-Compatible Schemas

Use familiar Zod syntax with AI-specific extensions. Same type inference, better handling of messy data.

Smart Coercion

Automatically converts types that LLMs commonly mix up: string numbers, ISO dates, boolean strings.

Extraction Helpers

Pull structured data from messy responses: JSON from markdown, lists from prose, code from explanations.

Graceful Errors

Detailed error messages that explain what was expected vs. received. Easy to log, easy to debug.

Why It Matters

90%
Less parsing code in your agents
Type Safe
Full TypeScript inference from schemas
Battle Tested
Handles edge cases from real LLM outputs

Learn More