Skip to content
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

Exclude model field from result #803

Open
iloveitaly opened this issue Jan 29, 2025 · 2 comments
Open

Exclude model field from result #803

iloveitaly opened this issue Jan 29, 2025 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@iloveitaly
Copy link

What I would like to do is have a pydantic model where the AI model call should fill out all the fields but one or two.

The idea here is I'm looping through a list of elements that need to be processed by a particular agent. I have an ID or some sort of deterministic value that I want set on each result and I don't want the agent to touch that field. I could create two separate pydantic models to represent these two states, but I'd rather have a single pydantic model and somehow mark one of the fields as handled by me instead of handled by the agent.

Is this sort of thing possible?

Here's a quick example.

class LabelResult(BaseModel):
    labels: list[str]
    reasoning: str
    summary: str
    message_id: str # I want the model to avoid filling this field in
@sydney-runkle sydney-runkle added the question Further information is requested label Jan 29, 2025
@sydney-runkle sydney-runkle self-assigned this Jan 29, 2025
@HamzaFarhan
Copy link

Yes. Like this:

from pydantic import BaseModel
from pydantic.json_schema import SkipJsonSchema


class LabelResult(BaseModel):
    labels: list[str]
    reasoning: str
    summary: str
    message_id: SkipJsonSchema[str]


LabelResult.model_json_schema()

{'properties': {'labels': {'items': {'type': 'string'},
                           'title': 'Labels',
                           'type': 'array'},
                'reasoning': {'title': 'Reasoning', 'type': 'string'},
                'summary': {'title': 'Summary', 'type': 'string'}},
 'required': ['labels', 'reasoning', 'summary'],
 'title': 'LabelResult',
 'type': 'object'}

I have successfully done this for skipping id Fields.

@mikeedjones
Copy link

Think that would mean this field will be missing if the schema is reproduced for another reason - like the swagger docs of a fastapi deployment which uses this model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants