Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
pydantic nested model response

I want to pass nested models into the response. I am trying by making object of 1 model then storing the related values to it, making object of 2nd model and storing related values to it and at the last trying to store thoes 2 model in the response model. Can you guys please help me out. Thank you

Models

class SetImageSetInput(BaseModel):
  profileId: str
  
  class Config:
    orm_mode = True



class ValidateFaceAlignmentInput(BaseModel):
  currentFrame: str
  
  class Config:
    orm_mode = True

class outputResponse(BaseModel):
    response1: ValidateFaceAlignmentInput
    response2: SetImageSetInput


SetImageSetInput.profileId="pic1"
ValidateFaceAlignmentInput.currentFrame="1"
outputResponse.response1 = SetImageSetInput
outputResponse.response2 = ValidateFaceAlignmentInput

return SetImageSetInput

But I am getting error while executing this api

pydantic.error_wrappers.ValidationError: 1 validation error for outputResponse
response -> response1
  field required (type=value_error.missing)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You just have to create instances of the corresponding classes and pass those to your reponse model object in the constructor. In code, it should read like

response = outputResponse(
    response1= ValidateFaceAlignmentInput(currentFrame ='1'), 
    response2=SetImageSetInput(profileId ='pic1'), 
)
return response
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!