-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
json
tool is inventing additional fields
#1125
Comments
Great call @adityaprakash-work. We've taken a stance so far of sticking very strictly to the JSON schema spec, which allows for additional fields unless you explicitly specify You can change this (I think, can't test atm) by creating a ConfigDict and setting extra="forbid": from pydantic import BaseModel, ConfigDict
class MyModel(BaseModel):
model_config = ConfigDict(extra="forbid") # Prevent extra fields
name: str
age: int
# Generate JSON Schema
json_schema = MyModel.model_json_schema()
import json
print(json.dumps(json_schema, indent=2)) That said... I think this is bad guidance library behavior, because most users don't know that JSON schema by default allows extra fields. This is a good push for us to discuss changing our default behavior. Tagging @hudson-ai and @Julian for further thoughts :) I think the field descriptions are another good area to discuss...we really should think about passing them by default. I wonder if we can have a kwarg on the |
(Maybe surprisingly, I'm not a pydantic expert! so I'd have to look closer to have a real opinion on what seems right) -- but the one thing I can say I'm aware of immediately is that I think pydantic is still working out what it wants its own defaults to be for some cases here -- specifically I've seen pydantic/pydantic#10785 cross my eye before. I think they asked me to offer an opinion somewhere on this, but I can't find it at the minute... |
The bug
What is the scope of
guidance.json
tool? I have tried it with very simple pydantic models and it works for them, but I get anomalous behavior when I nest models.There was one instance where I used the following code -
and got this,
It never seems to understand the dictionary part for Pascaltool and moreover forgets about the parameter 'd'.
To Reproduce
⬆️
System info (please complete the following information):
guidance.__version__
): 0.2.0The text was updated successfully, but these errors were encountered: