cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Generative AI
Explore discussions on generative artificial intelligence techniques and applications within the Databricks Community. Share ideas, challenges, and breakthroughs in this cutting-edge field.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Pydantic usage for structured output with provisioned LLM

fcardoze
New Contributor III

Hi,

I am looking for a resource that has examples of using Pydantic with a provisioned LLM on Databricks to get structured output.

I can find many examples of using Pydantic with LLMs, but not on the Databricks.

My use case is to extract text from images using one of the provisioned LLMs on Databricks into a structured format. For the LLM I would like to use Claude. Any help is greatly appreciated.

Regards,

Frank

4 REPLIES 4

jAAmes_bentley
Contributor

Are you looking to use models on batch or in a more traditional framework like LangChain? If the latter, you could use the Pydantic Output Parser with databricks-langchain?:

databricks-langchain ยท PyPI
PydanticOutputParser โ€” ๐Ÿฆœ๐Ÿ”— LangChain documentation

Thanks for the reply. LangChain is a framework that relies on Pydantic per my understanding. I was trying to keep the number of frameworks to a minimum for my use case which is strictly to get a structured output. I am still learning so perhaps I am approaching this the wrong way? 

jAAmes_bentley
Contributor

I think it depends what your overall usecase is.

  • If you're looking to extract text from images / documents specifically using Databricks then you could consider ai_parse which provides a structured extraction of text and OCR content from files: ai_parse_document function | Databricks Documentation
  • If you're looking to query an LLM in bulk / batch, you should consider calling Claude with ai_query, which supports structured outputs to a certain degree using the responseFormat argument: Databricks Documentation
  • If you're looking to ping an LLM endpoint in a more one-at-a-time way, then you'll need to query the Databricks endpoints somehow.

In the end, I wouldn't say LangChain is an unecasserily heavy framework, and it carries a lot of tools, docs, and examples which can help you upskill quickly. If you really want to keep it as minimal as possible, then use the openai library. However, as said, I'd personally recommend the LangChain links I've given above.

fcardoze
New Contributor III

Thank you!

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local communityโ€”sign up today to get started!

Sign Up Now