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

476
Views
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'main.SoluteSolvent'> is a valid pydantic field type

getting this error while executing the fast API code fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that <class 'main.SoluteSolvent'> is a valid pydantic field type

class SoluteSolvent():
    solvent: Text
    solute: Text

response = {}
@app.get('/predict')
def predict(sol:SoluteSolvent):
    data = sol.dict()
    solute = data['solute']
    solvent = data['solvent']
    results = predictions(solute, solvent)
    print(results)
    response["predictions"] = results[0].item()
    response["interaction_map"] = (results[1].detach().numpy()).tolist()
    return {'result':response}

I was actually trying to replicate the code I have written for prediction in flask in fast API.

response = {}
@app.route('/predict', methods=["POST", "GET"])
def predict():
    if request.method=='POST':
        solute = request.form["solute"]
        solvent = request.form["solvent"]

    else:
        solute = request.args.get("solute")
        solvent = request.args.get("solvent")

    results = predictions(solute, solvent)
    
    response["predictions"] = results[0].item()
    response["interaction_map"] = (results[1].detach().numpy()).tolist()
    return flask.jsonify({'result': response})
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The error says your type you pass to predict must be pydantic BaseModel (or dataclass from 0.67.0 version of FastApi). However it won't work that way (at least on get request), if you want to pass query params (suggested solution) list them in function:

@app.get('/predict')
def predict(solute: str, solvent: str):
   print(solute, solvent)

And use model for post request (which expects data in body):

from pydantic import BaseModel
class SoluteSolvent(BaseModel):
    solvent: str
    solute: str

@app.post('/predict')
def predict(sol:SoluteSolvent):
    print(sol.solute)

Or you can use underlying starlette Request directly

from fastapi import Request

async def predict(r: Request):
    print(r.query_params["solute"])
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!