davanstrien's picture
davanstrien HF Staff
Rewrite as clean HTML/JS app with dynamic label management
161b93c
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

  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

{
  "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

  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)

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!