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` (produces faster grammars + reduces hallucinations).
186
+
-`"additionalProperties": true` may produce keys that contain unescaped newlines.
185
187
- 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
188
- Can't mix `properties` w/ `anyOf` / `oneOf` in the same type (https://github.com/ggerganov/llama.cpp/issues/7703)
187
189
-[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 +205,11 @@ And a non-exhaustive list of other unsupported features that are unlikely to be
203
205
### A word about additionalProperties
204
206
205
207
> [!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`).
208
+
> The JSON schemas spec states `object`s accept [additional properties](https://json-schema.org/understanding-json-schema/reference/object#additionalproperties) by default.
209
+
> Since this is slow and seems prone to hallucinations, we default to no additional properties.
210
+
> You can set `"additionalProperties": true` in the the schema of any object to explicitly allow additional properties.
208
211
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:
212
+
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
213
211
214
```python
212
215
# pip install pydantic
@@ -215,14 +218,14 @@ from typing import Annotated, List
215
218
from pydantic import BaseModel, Extra, Field
216
219
classQAPair(BaseModel):
217
220
classConfig:
218
-
extra ='forbid'# triggers additionalProperties: false in the JSON schema
221
+
extra ='allow'# triggers additionalProperties: true in the JSON schema
QAPair ::= "{" space QAPair-question-kv "," space QAPair-concise-answer-kv "," space QAPair-justification-kv "}" space
298
+
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
313
key-facts-item ::= "\"" "- " key-facts-item-1{5,} "\"" space
303
314
key-facts-item-1 ::= dot
304
315
key-facts-kv ::= "\"key_facts\"" space ":" space key-facts
316
+
null ::= "null" space
317
+
number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
318
+
object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
305
319
question-answers ::= "[" space (question-answers-item ("," space question-answers-item)*)? "]" space
306
320
question-answers-item ::= "[" space question-answers-item-item ("," space question-answers-item-item){4,} "]" space
307
321
question-answers-item-item ::= QAPair
308
322
question-answers-kv ::= "\"question_answers\"" space ":" space question-answers
309
-
root ::= "{" space key-facts-kv "," space question-answers-kv "}" space
323
+
root ::= "{" space key-facts-kv "," space question-answers-kv ( "," space ( additional-kv ( "," space additional-kv )* ) )? "}" space
310
324
space ::= | " " | "\n" [ \t]{0,20}
311
325
string ::= "\"" char* "\"" space
326
+
value ::= object | array | string | number | boolean | null
312
327
```
313
328
314
329
</details>
315
330
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).
331
+
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