@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.
Test @tpmjs/tools-schema-infer (schemaInferTool) with AI-powered execution
0/2000 characters
Install this tool and use it with the AI SDK
npm install @tpmjs/tools-schema-inferpnpm add @tpmjs/tools-schema-inferyarn add @tpmjs/tools-schema-inferbun add @tpmjs/tools-schema-inferdeno add npm:@tpmjs/tools-schema-inferimport { schemaInferTool } from '@tpmjs/tools-schema-infer';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);Available configuration options
samplesarrayArray of sample data objects to analyze (minimum 1 sample)
optionsobjectSchema generation options
Schema extracted: 1/1/2026, 8:18:03 AM
Infer JSON Schema from sample data.
npm install @tpmjs/tools-schema-infer
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"]
// 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 } });
MIT
Downloads/month
0
Quality Score