Home/Tools/@tpmjs/tools-schema-infer

schemaInferTool

@tpmjs/tools-schema-infer

Infer a JSON Schema from sample data objects. Analyzes multiple samples to determine types, required fields, and structure. Useful for generating schemas from API responses or data samples.

Official
data
v0.1.0
MIT

Interactive Playground

Test @tpmjs/tools-schema-infer (schemaInferTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-schema-infer
pnpm add @tpmjs/tools-schema-infer
yarn add @tpmjs/tools-schema-infer
bun add @tpmjs/tools-schema-infer
deno add npm:@tpmjs/tools-schema-infer

2. Import the tool

import { schemaInferTool } from '@tpmjs/tools-schema-infer';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { schemaInferTool } from '@tpmjs/tools-schema-infer';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { schemaInferTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
samples
Required
Type: array

Array of sample data objects to analyze (minimum 1 sample)

options
Optional
Type: object

Schema generation options

Schema extracted: 1/1/2026, 8:18:03 AM

README

@tpmjs/tools-schema-infer

Infer JSON Schema from sample data.

Installation

npm install @tpmjs/tools-schema-infer

Usage

import { schemaInferTool } from '@tpmjs/tools-schema-infer';

const samples = [
  { name: 'Alice', age: 25, email: 'alice@example.com' },
  { name: 'Bob', age: 30, email: 'bob@example.com' }
];

const result = await schemaInferTool.execute({ samples });

console.log(result.schema);
// => {
//   $schema: "http://json-schema.org/draft-04/schema#",
//   type: "object",
//   properties: {
//     name: { type: "string" },
//     age: { type: "number" },
//     email: { type: "string" }
//   }
// }

console.log(result.sampleCount);
// => 2

console.log(result.properties);
// => ["name", "age", "email"]

Options

// Mark all fields as required
const result = await schemaInferTool.execute({
  samples: [{ name: 'Alice', age: 25 }],
  options: { required: true }
});

// Disallow additional properties
const result = await schemaInferTool.execute({
  samples: [{ name: 'Alice' }],
  options: { additionalProperties: false }
});

Features

  • Automatic type detection: Infers types from sample values
  • Multiple samples: Combine multiple samples for comprehensive schemas
  • Required fields: Optionally mark all properties as required
  • Nested objects: Handles nested object structures
  • Arrays: Detects array types and item schemas
  • JSON Schema standard: Generates standard JSON Schema Draft-04

Use Cases

  • Generate schemas from API responses
  • Create validation schemas from sample data
  • Document data structures automatically
  • Bootstrap TypeScript types from JSON examples

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
json-schema
schema
infer
data

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai