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

415
Views
FastAPI validation error on response_model

I have an FastAPI server that communicates with another API server (Lumen) to retrieve data, basically it only proxies the routes to the Lumen server.

Inside Lumen routes we have some validation rules and when we pass invalid body request it fails and returns 422 error code and a message. The problem is that my Fast API endpoint returns a response_model for the request in particular, so when a validation error occurs it tries to return the response model and the server fails because the code and message fields doesn't exist in our response_model

@router.post("/products/offers", response_model=OfferSearchResult, operation_id="offer_search")
async def offer_search(
    body: OfferSearchRequest,
    context: AppContext = Depends(get_context),
    max_per_product: Optional[conint(ge=1, le=100)] = Query(None, alias="maxPerProduct"),
    sort_by: Optional[OfferSort] = Query(None, alias="sortBy"),
) -> OfferSearchResult:

    offer_search_result = await OfferService(context).get_offers(body, max_per_product=max_per_product, sort_by=sort_by)
    return offer_search_result   

I tried to solve this by overriding validation_exception_handler but didn't work, how can I return that Lumen's validation error message to return as a fastAPI response?

over 4 years ago · Santiago Trujillo
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!