From eb4c669095e2c38e24ab6e9053ddfd63081cd4bf Mon Sep 17 00:00:00 2001 From: ochafik Date: Wed, 26 Jun 2024 09:19:02 +0100 Subject: [PATCH] Update README.md --- grammars/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/grammars/README.md b/grammars/README.md index 75c2b8e1d..877a7c1ed 100644 --- a/grammars/README.md +++ b/grammars/README.md @@ -199,6 +199,8 @@ Here is also a non-exhaustive list of **unsupported** features: > 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). > 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`). +#### Python + If you're using [Pydantic](https://pydantic.dev/) to generate schemas, you can disable additional properties with the `extra` config on each model class: ```python @@ -306,6 +308,8 @@ string ::= "\"" char* "\"" space +#### JavaScript + If you're using [Zod](https://zod.dev/), you can make your objects explicitly strict w/ `z.object(...).strict()` or `z.strictObject(...)`. 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).