Schema-aware structured output recovery for LLMs and agent workflows.
Recovers invalid structured outputs
Repairs missing required fields
Fixes enum violations
Validates and repairs tool-call payloads
Handles markdown-wrapped or text-wrapped JSON
Lightweight: 220M parameters
91.9% schema success on unseen schemas with randomized field names.
StructFix is a CodeT5+ 220M model fine-tuned to repair broken structured outputs using ConstraintDSL, a compact schema representation designed for small language models.
StructFix recovery flow
Problem
LLM and agent outputs often look almost correct but fail validation.
1dsl ="""FIELD status TYPE string VALUES success|error|pending REQUIRED yes
2FIELD result TYPE string REQUIRED yes"""34payload ='{"result":"Found 3 items"}'56print(repair_structured_output(dsl, payload))
Example output:
{"status":"success","result":"Found 3 items"}
Repair and validate against JSON Schema
Use StructFix as a recovery step, then validate with your normal validator.
1FIELD priority TYPE string VALUES low|medium|high REQUIRED yes
2FIELD description TYPE string REQUIRED yes
What It Repairs
Category
Support
Missing required fields
Yes
Invalid enums
Yes
Wrong types
Yes
Partial tool calls
Yes
Markdown-wrapped JSON
Yes
Extra text before or after JSON
Yes
Truncated objects and arrays
Yes
Python-like tool calls
Yes
When To Use It
Use StructFix when you have a schema or tool definition and need to recover a structured payload from an LLM, agent, ETL, or integration workflow.
Good fits:
Agent tool-call argument repair
JSON payload recovery before validation
Enum and required-field correction
Recovering JSON from assistant responses with prose or markdown
Lightweight local repair before retrying an expensive model call
Not a good fit:
Arbitrary data cleaning without a schema
High-stakes financial, medical, legal, or regulatory corrections without human validation
Inputs longer than the model context window
Tasks where preserving every original field name is mandatory without post-validation
ConstraintDSL
StructFix does not use raw JSON Schema directly at inference time. It expects a compact line-oriented schema format called ConstraintDSL.
Example:
text
1FIELD priority TYPE string VALUES low|medium|high REQUIRED yes
2FIELD description TYPE string REQUIRED yes
3FIELD customer_id TYPE integer REQUIRED no
Tool-call example:
text
1TOOL create_ticket
2ARG priority TYPE string VALUES low|medium|high REQUIRED yes
3ARG description TYPE string REQUIRED yes
4ARG customer_id TYPE integer REQUIRED no
Model input format:
text
1TASK repair_structured_output
23SPEC
4FIELD priority TYPE string VALUES low|medium|high REQUIRED yes
5FIELD description TYPE string REQUIRED yes
67BROKEN_OUTPUT
8{"priority":"urgent"}
ConstraintDSL exists because raw JSON Schema generalized poorly in this setup. With the same base model, data, and training procedure, ConstraintDSL improved unseen-schema schema success from 55.0% to 96.3%.
See ConstraintDSL for the DSL specification and compiler references.
Results
Main benchmark
Method
Schema Success
json-repair
65.2%
CodeT5+ + raw JSON Schema
55.0%
StructFix + ConstraintDSL
96.3%
StructFix + randomized fields
91.9%
Schema representation ablation
Test
Schema Success
Raw JSON Schema
55.0%
ConstraintDSL
96.3%
Randomized field names
91.9%
Per-corruption performance
Unseen schemas with random hex field names:
Corruption
StructFix
json-repair
invalid_enum
96.4%
0%
missing_required
92.2%
0%
null_required
97.9%
2.9%
wrong_type
92.0%
0%
tool_call_partial_args
90.9%
0%
tool_call_python_syntax
90.0%
0%
tool_call_wrong_param
93.8%
51.2%
agent_chain
87.2%
40.5%
Latency in the benchmark was about 690 ms/example for StructFix and 0.13 ms/example for json-repair.
Known Limitations
Field names unseen during training may be substituted by semantically similar names.
Synonym enum repair depends on lexical similarity and field-name semantics.
The model is English-oriented in the current version.
Maximum input length is 512 tokens.
Always validate the output against your schema after inference.
Not recommended for financial, medical, legal, or regulatory corrections without human review.
Example field-name substitutions observed in showcase validation:
DSL field name
Model output
action
active
records_processed
items_processed
contract_id
consign_id
to
strand
Research Findings
Raw JSON Schema generalized poorly for this 220M model: 55.0% schema success.
ConstraintDSL improved unseen-schema performance to 96.3%.
Randomized field names still achieved 91.9%, suggesting the model uses explicit constraints rather than only memorized field semantics.
Field names remain the most important DSL component in ablations.