https://github.com/loom-agents/schema
JSON Schemas, now.
https://github.com/loom-agents/schema
ajv json-schema openai-api runtime-validation schema-validation type type-inference type-safe typescript
Last synced: about 2 months ago
JSON representation
JSON Schemas, now.
- Host: GitHub
- URL: https://github.com/loom-agents/schema
- Owner: loom-agents
- Created: 2025-03-30T21:50:53.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-03-30T22:13:48.000Z (about 2 months ago)
- Last Synced: 2025-03-30T23:20:28.637Z (about 2 months ago)
- Topics: ajv, json-schema, openai-api, runtime-validation, schema-validation, type, type-inference, type-safe, typescript
- Language: TypeScript
- Homepage: https://loom-agents.github.io/docs/schema/
- Size: 50.8 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LOOM Schema
**A schema system that does exactly what you need.**
Type inference. Runtime validation. JSON Schema generation.
Zero build steps. No extra fluff. It just works.---
LOOM Schema was built because nothing else got this balance right:
- ✅ Type-safe and composable
- ✅ Validates at runtime
- ✅ Emits spec-compliant JSON Schema
- ❌ No codegen
- ❌ No decorators
- ❌ No build stepYou write schema-like TypeScript. You get real JSON Schema and real validation. That’s the whole point.
---
## Install
```sh
bun add loom-schema
```Everything’s bundled — including `ajv` and `ajv-formats`. No extra dependencies.
---
## Example
```ts
import { object, string, number, Infer } from "loom-schema";const User = object({
name: string({ minLength: 1 }),
age: number({ minimum: 0 }),
});type UserType = Infer;
const result = await User.validate({ name: "Ada", age: 32 });
if (!result.valid) {
console.error(result.errors);
}
```---
## Use Cases
Use LOOM Schema when you need to feed schemas into systems that **expect schemas**:
- OpenAI Function calling
- MCP & function serialization
- API endpoints with runtime enforcement
- Config validation and generation
- Frontend forms based on types
- CLI arg structure and validationIf it wants a schema, LOOM can give it one — safely, programmatically, and without ceremony.
---
## Features
- 📐 **TypeScript-first**: deeply inferred types
- 🧩 **Composable fragments**: mix and reuse schema pieces with ease
- 🎛 **All the basics**: `allOf`, `anyOf`, `oneOf`, conditionals, etc.
- 📄 **Standards-based**: JSON Schema 2020-12 compliance
- 🧪 **Runtime validation**: powered by AJV with formats out of the box
- 📦 **No config, no build step, no codegen**---
## Schema Inference
```ts
const Config = object({
apiKey: string(),
retries: number({ default: 3 }),
});type ConfigType = Infer;
// {
// apiKey: string;
// retries: number;
// }
```---
## Composition
```ts
import { allOf, object, string } from "loom-schema";const WithId = object({ id: string({ format: "uuid" }) });
const Product = allOf([
WithId,
object({
name: string(),
description: string(),
}),
]);
```---
## Validation
```ts
const result = await Product.validate({
id: "123e4567-e89b-12d3-a456-426614174000",
name: "Widget",
description: "An example widget",
});
```Returns `{ valid, errors }` from AJV — clean and informative.
---
## Philosophy
LOOM Schema wasn’t built to be trendy. It was built to be **minimal**, **practical**, and **actually usable** across systems that expect real JSON Schema. It gives you the right pieces to build and validate data shapes at runtime — without taking over your project.
---
**You write types.**
**You get schemas.**
**That’s it.**