Skip to main content

Questions tagged [pydantic]

Pydantic is a library for data validation and settings management based on Python type hinting and variable annotations. You can use Pydantic for defining schemas of complex structures in Python.

2 votes
1 answer
18 views

How to write Decorator or Wrapper over @validator in Pyndantic to print success msg after validator runs successfully

from pydantic import BaseModel, validator def validator_decorator(message): def decorator(func): def wrapper(cls, v, values, config, field): # Call the original validator ...
Kuruva Vinod Kumar's user avatar
0 votes
0 answers
15 views

Decorator over Pydantic Validator

@validator('name') def name_must_contain_space(cls, v): if ' ' not in v: raise ValueError('must contain a space') return v Now Can I write a decorator over @validator to print ...
Kuruva Vinod Kumar's user avatar
1 vote
1 answer
29 views

Export Pydantic model classes (not instances) to JSON

I understand that Pydantic can export models to JSON, see ref. But in practice, this means instances of a model: from datetime import datetime from pydantic import BaseModel class BarModel(BaseModel):...
jbuddy_13's user avatar
  • 1,152
0 votes
0 answers
33 views

Is it possible (or recommended?) to mix abstract base classes with Pydantic BaseModel?

In the example code below, I tried to combine abstract base classes with Pydantic. I wanted to write this code because I had an existing type Ticker which has two implementations. It can either be ...
FreelanceConsultant's user avatar
0 votes
2 answers
63 views

How to clear pydantic object to default values?

I need default values to be cleared in a Pydantic model. I cannot recreate the object because, in my use case, it has references that need to be preserved. Could you please show me the best practices ...
pyjedy's user avatar
  • 595
0 votes
1 answer
38 views

Pydantic 2.7 date_from_datetime_parsing error

I have a model in pydantic in the following format: class CommonResponse(_BaseSchema): """ Schema com os campos padrões dos objetos response """ legal_nature: str ...
Lucca Torrezilha Soares's user avatar
0 votes
0 answers
28 views

Dagster: Connect assets with operations to validate data model

I recently discovered dagster as an alternative of airflow and I really like it. Great job from the team. However, I am looking for some help regarding a problem I am facing. I have several assets ...
PicxyB's user avatar
  • 737
-2 votes
0 answers
38 views

How to use type(obj)([......]) to create class instance [duplicate]

Please see py-automapper sourcecode class Address(BaseModel): street: Optional[str] number: Optional[int] zip_code: Optional[int] city: Optional[str] address = ...
user26374984's user avatar
0 votes
0 answers
50 views

Attribute Scope Issues with FastEmbedEmbeddings in Flask-based RAG Server

I am very new to python... in every way. Which, may be the root of the problem. I was attempting to follow a RAG tutorial watching Llama3 Full Rag - API with Ollama, LangChain and ChromaDB with Flask ...
Nolan Robidoux's user avatar
0 votes
0 answers
22 views

Validate a single boolean value using pydantic

I am using Pydantic extensively in my repository. Pydantic is good at validating models. However, there are some cases where I might want to validate a single value, in this case a boolean. There are ...
simplegamer's user avatar
0 votes
1 answer
44 views

Trying to create a one-to-many relationship in both directions

All, thanks for taking the time to help. Basically, I have a table called Task that has a one-to-many relationship with a table called Label. This works just fine. I can assign every label I create ...
Jon Hayden's user avatar
2 votes
1 answer
63 views

Set Pydantic BaseModel field type dynamically when instantiating an instance?

With Pydantic is it possible to build a model where the type of one of its fields is set via an argument when creating an instance? For example: class Animal(BaseModel): name: str class Dog(...
Matt Sanders's user avatar
  • 9,833
0 votes
1 answer
49 views

Is it possible to get a dict of fields with FieldInfo from the Pydantic Dataclass?

When creating classes by inheriting from BaseModel, I can use the model_fields property to get a dict of field names, and FieldInfo, but how can I do it if I use the Pydantic Dataclass decorator ...
Michal's user avatar
  • 961
2 votes
2 answers
76 views

How do I best send Pydantic model objects via put requests?

I am quite new to Pydantic. I have noticed how it is often used in validating input to FastAPI. I have a project where I need to send something to another application's API endpoint and thought I ...
Thomas Arildsen's user avatar
0 votes
0 answers
49 views

CrewAI Langchain StructuredTool JSON

I have a custom tool using the langchain StructuredTool.from_function from langchain.tools.base import StructuredTool from langchain_core.pydantic_v1 import BaseModel, Field create_draft_tool = ...
Chris Johnston's user avatar

15 30 50 per page
1
2 3 4 5
150