Universal JSON Extractor (adityapande403/universal-json-extractor)

A fine-tuned language model specialized in schema-guided information extraction. Given an arbitrary JSON Schema and noisy unstructured text (OCR outputs, logs, tickets, messy tables, or customer chats), this model produces strictly validated, schema-compliant JSON objects without hallucinations.

Key Features

  • Strict Schema Compliance: Trained on 30,000 diverse synthetic extraction examples with strict JSON Schema constraints.
  • Zero Hallucination Guard: Employs non-hallucination and abstention policies when required fields are missing from untrusted input text.
  • Anti-Prompt-Injection: Source text is treated strictly as passive data inside <UNTRUSTED_SOURCE_TEXT> boundaries.
  • Lightweight & Local: Fine-tuned on Qwen/Qwen2.5-1.5B-Instruct for fast local execution on consumer GPUs (e.g., RTX 5060 Ti / RTX 40-series) and CPU backends via GGUF/Ollama.

Usage Example

from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import json

base_model = "Qwen/Qwen2.5-1.5B-Instruct"
adapter_id = "adityapande403/universal-json-extractor"

tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(base_model, device_map="auto", torch_dtype="auto")
model = PeftModel.from_pretrained(model, adapter_id)

schema = {
    "type": "object",
    "properties": {
        "device_id": {"type": "string"},
        "temperature_c": {"type": ["number", "null"]},
        "error_code": {"type": ["string", "null"]}
    },
    "required": ["device_id", "temperature_c"],
    "additionalProperties": False
}

source_text = "dev=EC200U-07; temp 72.4C; modem ERROR 304 at 2026/10/21 14:30:11"

prompt = f"""<|im_start|>system
You are a precise, deterministic information extraction engine. Return ONLY the raw JSON object conforming to the schema.
<|im_end|>
<|im_start|>user
<TARGET_JSON_SCHEMA>
{json.dumps(schema, indent=2)}
</TARGET_JSON_SCHEMA>
<UNTRUSTED_SOURCE_TEXT>
{source_text}
</UNTRUSTED_SOURCE_TEXT>
Output strictly the conforming JSON object now:<|im_end|>
<|im_start|>assistant
"""

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
output_text = tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
print(output_text)

Repository

For full data generation, training scripts, evaluation benchmarks, and FastAPI deployment code, see: GitHub Repository

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Adityapande403/universal-json-extractor

Adapter
(1647)
this model