Get LLM output as Python object with Langchain and Pydantic | Hands-on tutorial

preview_player
Показать описание
The #Pydantic output parser is a tool that allows users to define a JSON schema to query LLMs for outputs that adhere to that schema. This is pivotal for applications that require structured data, as it ensures outputs conform to predefined formats. The parser leverages Pydantic’s BaseModel for data validation and type checking.

With this tutorial you will learn to: set up the data model in a way that Langchain’s output parser can be used to generate structured data.

For example, you can grab from #LLM not a plain text (as an answer), but re-usable Python objects, such as Python list, dictionary, Pandas dataframe and more.

This functionality allows you to create super powerful LLM applications where any kind of data transformation, parse or passing to ML models (such as example) are required.

To utilize this parser, one must define the data structure using Pydantic’s BaseModel. You will learn that in the tutorial.

Useful links and references:

In this tutorial I used OpenAI's ChatGPT API to support LLM. Feel free to use any supported LLM using LangChain (now testing on IBM WatsonX).

The content of the tutorial:
0:00 - Main idea using Pydantic with Langchain
1:09 - Implementation scheme for hands-on
3:29 - Hands-on part (coding)
15:06 - BONUS: Github repo

#langchain

Happy learning!
Рекомендации по теме
Комментарии
Автор

Thank you for watching this video. I really appreciate your time. If you have any comments and experience to share, do not hesitate to leave it here in the comments!
Have a nice day!

- - -

DataScienceGarage
Автор

Thank you so much for your clarifications. You have a WONDERFUL STYLE in delivering the ideas in a very simple and understandable way. You really deserve 10 stars out of 10.👏👏👏👏

ahassan
Автор

If you use models other than open ai will it work??

sridevigogusetty
Автор

Powerful video and up to date as opposed to others right now! Thank you Data Science Garage

RollingcoleW
Автор

you're a legend mate. very well explained!

Alex-pdxc
Автор

huge thanks for this interesting video!

israeabdelbar
Автор

Can you please make a video about streaming in langchain. I hope you have time to present how it is used. Thank you so much.

ahassan