From the chatlas docs:
chatlas: Chat.extract_data() methodpydantic: data model from BaseModel, with optional Field descriptionsimport chatlas as ctl
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
chat = ctl.ChatOpenAI()
chat.extract_data(
"My name is Susan and I'm 13 years old",
data_model=Person,
)output:
{"name": "Susan", "age": 13}
Field(): add a description to the modelimport chatlas as ctl
from pydantic import BaseModel, Field
class Person(BaseModel):
"""A person"""
name: str = Field(description="Name")
age: int = Field(description="Age, in years")
hobbies: list[str] | None = Field(
description="List of hobbies. Should be exclusive and brief."
)
chat = ctl.ChatAnthropic() # changed to Anthropic
chat.extract_data(
"My name is Susan and I'm 13 years old",
data_model=Person,
)Demo Chatlas docs: https://posit-dev.github.io/chatlas/structured-data/article-summary.html
Demo Chatlas docs: https://posit-dev.github.io/chatlas/structured-data/entity-recognition.html
Demo Chatlas docs: https://posit-dev.github.io/chatlas/structured-data/sentiment-analysis.html
Demo Chatlas Docs: https://posit-dev.github.io/chatlas/structured-data/classification.html
Demo Chatlas Docs: https://posit-dev.github.io/chatlas/structured-data/multi-modal.html
Demo: https://github.com/chendaniely/nydsaic2025-llm/blob/main/code/04-structured/02-image.py
Demo: https://github.com/chendaniely/nydsaic2025-llm/blob/main/code/04-structured/03-pdf.py
The New York Data Science & AI Conference. 2025. https://github.com/chendaniely/nydsaic2025-llm