You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is also a list of known limitations (contributions welcome):
184
184
185
+
-`additionalProperties` defaults to `false` (faster grammars + reduces hallucinations)
185
186
- Unsupported features are skipped silently. It is currently advised to use the command-line Python converter (see above) to see any warnings, and to inspect the resulting grammar / test it w/ [llama-gbnf-validator](../examples/gbnf-validator/gbnf-validator.cpp).
186
187
- Can't mix `properties` w/ `anyOf` / `oneOf` in the same type (https://github.com/ggerganov/llama.cpp/issues/7703)
187
188
-[prefixItems](https://json-schema.org/draft/2020-12/json-schema-core#name-prefixitems) is broken (but [items](https://json-schema.org/draft/2020-12/json-schema-core#name-items) works)
@@ -203,10 +204,11 @@ And a non-exhaustive list of other unsupported features that are unlikely to be
203
204
### A word about additionalProperties
204
205
205
206
> [!WARNING]
206
-
> By default, `object`s accept [additional properties](https://json-schema.org/understanding-json-schema/reference/object#additionalproperties), which you might not want / not expect, and which will make sampling slower (not just because of the extra tokens, but also generates a slower grammar).
207
-
> You can set `"additionalProperties": false` on the schema of any object to ensure only properties listed in `properties` are generated (not needed for non-`object` types, e.g. `array` or `string`).
207
+
> The JSON schemas spec states `object`s accept [additional properties](https://json-schema.org/understanding-json-schema/reference/object#additionalproperties) by default.
208
+
> Since this is slow and seems prone to hallucinations, we default to no additional properties.
209
+
> You can set `"additionalProperties": true` in the the schema of any object to explicitly allow additional properties.
208
210
209
-
If you're using [Pydantic](https://pydantic.dev/) to generate schemas, you can disable additional properties with the `extra` config on each model class:
211
+
If you're using [Pydantic](https://pydantic.dev/) to generate schemas, you can enable additional properties with the `extra` config on each model class:
210
212
211
213
```python
212
214
# pip install pydantic
@@ -215,14 +217,14 @@ from typing import Annotated, List
215
217
from pydantic import BaseModel, Extra, Field
216
218
classQAPair(BaseModel):
217
219
classConfig:
218
-
extra ='forbid'# triggers additionalProperties: false in the JSON schema
220
+
extra ='allow'# triggers additionalProperties: true in the JSON schema
QAPair ::= "{" space QAPair-question-kv "," space QAPair-concise-answer-kv "," space QAPair-justification-kv "}" space
297
+
QAPair ::= "{" space QAPair-question-kv "," space QAPair-concise-answer-kv "," space QAPair-justification-kv ( "," space ( QAPair-additional-kv ( "," space QAPair-additional-kv )* ) )? "}" space
key-facts ::= "[" space (key-facts-item ("," space key-facts-item)*)? "]" space
302
312
key-facts-item ::= "\"" "- " key-facts-item-1{5,} "\"" space
303
313
key-facts-item-1 ::= dot
304
314
key-facts-kv ::= "\"key_facts\"" space ":" space key-facts
315
+
null ::= "null" space
316
+
number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
317
+
object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
305
318
question-answers ::= "[" space (question-answers-item ("," space question-answers-item)*)? "]" space
306
319
question-answers-item ::= "[" space question-answers-item-item ("," space question-answers-item-item){4,} "]" space
307
320
question-answers-item-item ::= QAPair
308
321
question-answers-kv ::= "\"question_answers\"" space ":" space question-answers
309
-
root ::= "{" space key-facts-kv "," space question-answers-kv "}" space
322
+
root ::= "{" space key-facts-kv "," space question-answers-kv ( "," space ( additional-kv ( "," space additional-kv )* ) )? "}" space
310
323
space ::= | " " | "\n" [ \t]{0,20}
311
324
string ::= "\"" char* "\"" space
325
+
value ::= object | array | string | number | boolean | null
312
326
```
313
327
314
328
</details>
315
329
316
-
If you're using [Zod](https://zod.dev/), you can make your objects explicitly strict w/ `z.object(...).strict()` or `z.strictObject(...)`.
317
-
318
-
Note however that [zod-to-json-schema](https://github.com/StefanTerdell/zod-to-json-schema) currently always seems to set `"additionalProperties": false` anyway (even w/ zod schemas on which `nonstrict()` / `passthrough()` was called).
330
+
If you're using [Zod](https://zod.dev/), you can make your objects to explicitly allow extra properties w/ `nonstrict()` / `passthrough()` (or explicitly no extra props w/ `z.object(...).strict()` or `z.strictObject(...)`) but note that [zod-to-json-schema](https://github.com/StefanTerdell/zod-to-json-schema) currently always sets `"additionalProperties": false` anyway.
0 commit comments