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

Custom type with Annotated and pydantic #313

Open
kondera opened this issue Sep 2, 2024 · 0 comments
Open

Custom type with Annotated and pydantic #313

kondera opened this issue Sep 2, 2024 · 0 comments

Comments

@kondera
Copy link

kondera commented Sep 2, 2024

Hey,

I've been loving kor so far (especially how it returns dicts with raw, errrors and validated data).
But is there some way to create your own "types" with validators with pydantic 2 e.g.:

PhoneNumber = Annotated[
    str,
    AfterValidator(lambda num: ''.join(x for x in num if x.isdigit())),
    Field(
        description="Phone number in E.164 format",
        examples=["505505505"],
        min_length=9,
        max_length=9,
    ),
]

It would be quite useful for extraction tasks.
For now I've been kinda creating 2 models - 1 for kor which just gets strings, and 2nd to create more strict that validates the previous model, which is not ideal, but gets the job done.

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

No branches or pull requests

1 participant