Development6 min readDecember 20, 2024

Custom Schemas: Extract Exactly What You Need

Define your own JSON schema and get clean arrays of prices, features, or any structured data from web research.

UnforgeAPI Team

Share:

The Generic Output Problem

Standard LLM APIs return generic, unstructured text:

Based on my research, Tesla's market cap is $850B, which is significantly higher than Rivian's $14B. Tesla has been growing steadily with a 23% increase over the past year. In comparison, Rivian has struggled with production delays...

For AI agents, this is problematic:

  • Requires complex parsing
  • Inconsistent formatting
  • Hard to extract specific fields
  • Error-prone regex patterns

The Custom Schema Solution

Deep Research API lets you define exactly what you want:

Basic Types

const schema = {
  price: "number",
  change: "string",
  volume: "number"
}

Enums

const schema = {
  sentiment: "bullish | bearish | neutral",
  trend: "uptrend | downtrend | sideways"
}

Arrays

const schema = {
  prices: "number[]",
  features: "string[]",
  key_events: "string[]"
}

Nested Objects

const schema = {
  company: {
    name: "string",
    market_cap: "number",
    sector: "string"
  },
  metrics: {
    revenue: "number",
    growth: "number",
    margin: "number"
  }
}

Real-World Examples

Crypto Price Extraction

const cryptoData = await deepResearch({
  query: "Bitcoin, Ethereum, Solana prices",
  mode: "extract",
  schema: {
    bitcoin: { price: "number", change_24h: "string" },
    ethereum: { price: "number", change_24h: "string" },
    solana: { price: "number", change_24h: "string" }
  }
})

// Returns:
{
  "bitcoin": { "price": 95000, "change_24h": "+2.3%" },
  "ethereum": { "price": 3200, "change_24h": "-1.1%" },
  "solana": { "price": 145, "change_24h": "+5.7%" }
}

Product Feature Comparison

const comparison = await deepResearch({
  query: "iPhone 16 vs Samsung Galaxy S25",
  mode: "extract",
  schema: {
    iphone: {
      price: "number",
      screen_size: "string",
      battery: "string",
      features: "string[]"
    },
    samsung: {
      price: "number",
      screen_size: "string",
      battery: "string",
      features: "string[]"
    }
  }
})

// Returns structured comparison data
// Easy to display in UI

Academic Paper Analysis

const papers = await deepResearch({
  query: "Recent AI research papers on transformers",
  mode: "extract",
  schema: {
    papers: [{
      title: "string",
      authors: "string[]",
      year: "number",
      citations: "number",
      summary: "string"
    }]
  }
})

// Returns array of structured paper data

Advanced Patterns

Conditional Fields

const schema = {
  available: "boolean",
  price: "number | null",  // Only if available
  url: "string | null"      // Only if available
}

Validation Rules

const schema = {
  email: {
    type: "string",
    format: "email",
    required: true
  },
  age: {
    type: "number",
    min: 0,
    max: 120
  }
}

Best Practices

  1. Be Specific: Define exact field names
  2. Use Types: Specify string, number, boolean, arrays
  3. Nest When Needed: Group related fields in objects
  4. Add Enums: For known value sets
  5. Document: Comment complex schemas

Get Started

Extract exactly what you need with custom schemas.

Get Your API Key

Read Schema Documentation

Tags:DevelopmentAI AgentsDeep Research

Ready to Build with AI?

Join developers using UnforgeAPI to ship intelligent applications faster with our Hybrid RAG engine.