luis-otte commited on
Commit
8c580ef
·
verified ·
1 Parent(s): 5c578f4

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +161 -0
README.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - schema-validation
5
+ - structured-output
6
+ - tool-calling
7
+ - agent-workflows
8
+ - constraint-dsl
9
+ - json-schema
10
+ ---
11
+
12
+ # ConstraintDSL
13
+
14
+ A lightweight domain-specific language for representing JSON Schema constraints, optimized for small language model consumption.
15
+
16
+ ## Why ConstraintDSL?
17
+
18
+ Raw JSON Schema is a hierarchical, nested format designed for validation — not for language model reasoning. ConstraintDSL flattens schema constraints into explicit, line-oriented statements that small models (200M–1.5B parameters) can parse and follow reliably.
19
+
20
+ ### Empirical evidence
21
+
22
+ | Schema representation | Schema success (unseen schemas) |
23
+ |-----------------------|:------------------------------:|
24
+ | Raw JSON Schema | 55.0% |
25
+ | **ConstraintDSL** | **96.3%** |
26
+ | ConstraintDSL (random field names) | **91.9%** |
27
+
28
+ Same model (CodeT5+ 220M), same training procedure, same data volume. Only the schema representation changed.
29
+
30
+ ## Specification v1
31
+
32
+ ### Field declaration
33
+
34
+ ```
35
+ FIELD <path> TYPE <type> [VALUES <v1|v2|...>] REQUIRED <yes|no>
36
+ ```
37
+
38
+ ### Path notation
39
+
40
+ - Flat: `FIELD priority TYPE string REQUIRED yes`
41
+ - Nested: `FIELD customer.name TYPE string REQUIRED yes`
42
+ - Array of primitives: `FIELD tags[] TYPE string REQUIRED no`
43
+ - Array of objects: `FIELD items[].sku TYPE string REQUIRED yes`
44
+
45
+ ### Types
46
+
47
+ - `string`, `integer`, `number`, `boolean`, `null`
48
+ - `string_email`, `string_date-time`, `string_uri` (format variants)
49
+ - `string` with `VALUES` clause for enums
50
+
51
+ ### Tool declaration
52
+
53
+ ```
54
+ TOOL <name>
55
+ ARG <path> TYPE <type> [VALUES <v1|v2|...>] REQUIRED <yes|no>
56
+ ```
57
+
58
+ ## Examples
59
+
60
+ ### Simple object
61
+
62
+ JSON Schema:
63
+ ```json
64
+ {"type":"object","properties":{"priority":{"type":"string","enum":["low","medium","high"]},"description":{"type":"string"}},"required":["priority"]}
65
+ ```
66
+
67
+ ConstraintDSL:
68
+ ```
69
+ FIELD priority TYPE string VALUES low|medium|high REQUIRED yes
70
+ FIELD description TYPE string REQUIRED no
71
+ ```
72
+
73
+ ### Nested object
74
+
75
+ ```
76
+ FIELD customer.name TYPE string REQUIRED yes
77
+ FIELD customer.age TYPE integer REQUIRED no
78
+ FIELD ticket.priority TYPE string VALUES low|medium|high REQUIRED yes
79
+ ```
80
+
81
+ ### OpenAI tool
82
+
83
+ ```
84
+ TOOL create_ticket
85
+ ARG priority TYPE string VALUES low|medium|high REQUIRED yes
86
+ ARG description TYPE string REQUIRED yes
87
+ ARG customer_id TYPE integer REQUIRED no
88
+ ```
89
+
90
+ ### MCP tool
91
+
92
+ ```
93
+ TOOL read_sensor
94
+ ARG sensor_id TYPE string REQUIRED yes
95
+ ARG metric TYPE string VALUES temperature|humidity|pressure REQUIRED yes
96
+ ```
97
+
98
+ ## Input format for models
99
+
100
+ ```
101
+ TASK repair_structured_output
102
+
103
+ SPEC
104
+ FIELD priority TYPE string VALUES low|medium|high REQUIRED yes
105
+ FIELD description TYPE string REQUIRED yes
106
+
107
+ BROKEN_OUTPUT
108
+ {"priority":"urgent"}
109
+ ```
110
+
111
+ Target output:
112
+ ```json
113
+ {"priority":"high","description":""}
114
+ ```
115
+
116
+ ## Source compilers
117
+
118
+ Compilers are provided for:
119
+ - JSON Schema → ConstraintDSL
120
+ - OpenAI function/tool definitions → ConstraintDSL
121
+ - Anthropic tool definitions → ConstraintDSL
122
+ - MCP tool definitions → ConstraintDSL
123
+
124
+ See `schema_compiler.py` for the reference implementation.
125
+
126
+ ## Ablation results
127
+
128
+ | DSL variant | Schema success |
129
+ |------------|:--------------:|
130
+ | Full DSL | 96.3% |
131
+ | Shuffled field names | 73.4% |
132
+ | Shuffled enum values | 89.8% |
133
+ | Shuffled required flags | 93.2% |
134
+ | Field names only | 72.2% |
135
+ | No DSL | 78.4% |
136
+
137
+ Field names are the most critical component (-22.9pp when shuffled), followed by enum values (-6.5pp) and required flags (-3.1pp).
138
+
139
+ ## Known limitations
140
+
141
+ ConstraintDSL significantly improves structural reasoning in small models, but does not fully eliminate lexical bias. Models trained with ConstraintDSL may still substitute field names with semantically similar alternatives from their training vocabulary (e.g., `action` → `active`). This is a model-level limitation, not a DSL limitation — the DSL provides correct field names, but the model may not faithfully reproduce them.
142
+
143
+ ## Related
144
+
145
+ - [StructFix (CodeT5+ 220M)](https://huggingface.co/ottema/structfix-codet5p-220m) — model trained with ConstraintDSL
146
+ - [StructFix-Bench](https://huggingface.co/datasets/ottema/structfix-bench) — benchmark dataset
147
+
148
+ ## License
149
+
150
+ Apache-2.0
151
+
152
+ ## Citation
153
+
154
+ ```bibtex
155
+ @software{structfix_constraint_dsl,
156
+ title = {ConstraintDSL: Schema Representation for Small Language Models},
157
+ author = {Ottema},
158
+ year = {2026},
159
+ url = {https://huggingface.co/datasets/ottema/constraint-dsl}
160
+ }
161
+ ```