metadata
title: JSON Schema Generator for Text Classification
emoji: π·οΈ
colorFrom: blue
colorTo: purple
sdk: static
app_file: index.html
pinned: false
license: mit
JSON Schema Generator for Text Classification
A simple, user-friendly tool to generate JSON schemas for text classification tasks. Perfect for structured generation with Large Language Models (LLMs).
π― Purpose
This tool helps you create properly formatted JSON schemas that can be used with:
- LM Studio - Structured Output field
- OpenAI API -
response_format
parameter - llama.cpp - Grammar constraints
- Any LLM API supporting JSON schema validation
π Features
- Single-label classification - Choose one category from a list
- Multi-label classification - Select multiple applicable categories
- Live preview - See your schema and example outputs in real-time
- Copy & Download - Easy export options for your schemas
- Beginner-friendly - No JSON knowledge required
π How to Use
Select Classification Type
- Single: For mutually exclusive categories (e.g., sentiment: positive OR negative)
- Multi: For multiple applicable labels (e.g., topics: can be both "sports" AND "politics")
Add Your Labels
- Enter the categories you want to classify text into
- Add optional descriptions for clarity
- Use the β button to add more labels
Configure Options (Optional)
- Change the field name (default: "classification")
- Set whether the field is required
- For multi-label: set min/max number of selections
Get Your Schema
- Copy the generated JSON schema
- Download as a .json file
- See example outputs
π§ Example Use Cases
Sentiment Analysis
{
"type": "object",
"properties": {
"sentiment": {
"type": "string",
"enum": ["positive", "negative", "neutral"]
}
},
"required": ["sentiment"]
}
Topic Classification (Multi-label)
{
"type": "object",
"properties": {
"topics": {
"type": "array",
"items": {
"type": "string",
"enum": ["technology", "health", "finance", "education", "entertainment"]
},
"uniqueItems": true
}
}
}
π€ Integration Examples
LM Studio
- Generate your schema using this tool
- Copy the schema
- In LM Studio, paste into the "Structured Output" field
- The model will only generate JSON matching your schema
OpenAI API (Python)
import openai
# Your generated schema
response_format = {
"type": "json_schema",
"json_schema": {
"name": "classification",
"schema": { ... } # Paste your schema here
}
}
response = openai.chat.completions.create(
model="gpt-4",
messages=[...],
response_format=response_format
)
π Resources
π οΈ Technical Details
This tool generates JSON Schema Draft 7 compatible schemas that enforce:
- Valid JSON structure
- Type constraints (string, array)
- Enum restrictions for valid label values
- Array uniqueness for multi-label classification
- Optional min/max constraints for array lengths
π License
MIT License - Feel free to use and modify!