You've been doing this for a while now:
response = client . chat . completions . create ( model = " gemini-2.0-flash " , messages = [{ " role " : " user " , " content " : f " Extract the following fields from this text: { fields } . Text: { text } " }] ) data = json . loads ( response . choices [ 0 ]. message . content ) proposal = Proposal ( ** data )
Enter fullscreen mode
Exit fullscreen mode
Parse the response. Hope the JSON is valid. Add a retry. Add a fallback. Add validation. Repeat for every model in your app.
There's a better way.
Meet exomodel
exomodel is an open-source Python framework that turns your Pydantic models into autonomous agents.…