| | --- |
| | 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 |
| |
|
| | 1. **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") |
| |
|
| | 2. **Add Your Labels** |
| | - Enter the categories you want to classify text into |
| | - Add optional descriptions for clarity |
| | - Use the β button to add more labels |
| |
|
| | 3. **Configure Options** (Optional) |
| | - Change the field name (default: "classification") |
| | - Set whether the field is required |
| | - For multi-label: set min/max number of selections |
| |
|
| | 4. **Get Your Schema** |
| | - Copy the generated JSON schema |
| | - Download as a .json file |
| | - See example outputs |
| |
|
| | ## π§ Example Use Cases |
| |
|
| | ### Sentiment Analysis |
| | ```json |
| | { |
| | "type": "object", |
| | "properties": { |
| | "sentiment": { |
| | "type": "string", |
| | "enum": ["positive", "negative", "neutral"] |
| | } |
| | }, |
| | "required": ["sentiment"] |
| | } |
| | ``` |
| |
|
| | ### Topic Classification (Multi-label) |
| | ```json |
| | { |
| | "type": "object", |
| | "properties": { |
| | "topics": { |
| | "type": "array", |
| | "items": { |
| | "type": "string", |
| | "enum": ["technology", "health", "finance", "education", "entertainment"] |
| | }, |
| | "uniqueItems": true |
| | } |
| | } |
| | } |
| | ``` |
| |
|
| | ## π€ Integration Examples |
| |
|
| | ### LM Studio |
| | 1. Generate your schema using this tool |
| | 2. Copy the schema |
| | 3. In LM Studio, paste into the "Structured Output" field |
| | 4. The model will only generate JSON matching your schema |
| |
|
| | ### OpenAI API (Python) |
| | ```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 |
| |
|
| | - [JSON Schema Documentation](https://json-schema.org/) |
| | - [OpenAI Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs) |
| | - [LM Studio Documentation](https://lmstudio.ai/docs) |
| |
|
| | ## π οΈ 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! |
| |
|