x if the LLM says “yes”, do y if it says “no”.In addition to type hints, you can add descriptions to your fields.
import chatlas as ctl
from pydantic import BaseModel
class ModelResult(BaseModel):
model: str
dataset: str
metric: str
value: float
class PaperResults(BaseModel):
results: list[ModelResult]
abstract = """ResNet-50 achieves 93.2% top-1 accuracy on CIFAR-10 and 76.1% on
ImageNet. A fine-tuned ViT-B/16 reaches 98.1% on CIFAR-10."""
chat = ctl.ChatBedrockAnthropic()
chat.chat_structured(abstract, data_model=PaperResults)import chatlas as ctl
from pydantic import BaseModel
class PlotInfo(BaseModel):
chart_type: str
x_label: str
y_label: str
trend: str
chat = ctl.ChatBedrockAnthropic()
chat.chat_structured(
ctl.content_image_url("https://matplotlib.org/stable/_images/sphx_glr_simple_plot_001.png"),
data_model=PlotInfo,
)import chatlas as ctl
from pydantic import BaseModel
from typing import Literal
class IssueLabel(BaseModel):
label: Literal["bug", "enhancement", "docs", "question"]
confidence: Literal["low", "medium", "high"]
chat = ctl.ChatBedrockAnthropic()
chat.chat_structured(
"The `plt.show()` call hangs indefinitely on macOS with the Tk backend.",
data_model=IssueLabel,
)import chatlas as ctl
from pydantic import BaseModel, Field
class Citation(BaseModel):
authors: list[str]
year: int
title: str
journal: str | None = Field(description="Journal name; None for preprints")
doi: str | None = Field(description="DOI if present, otherwise None")
ref = "Harris et al. (2025). NumPy 2.0: Array API Standard Conformance. arXiv:2501.12345"
chat = ctl.ChatBedrockAnthropic()
chat.chat_structured(ref, data_model=Citation)Try extracting structured data from this PDF:
https://storage.googleapis.com/generativeai-downloads/data/pdf_structured_outputs/invoice.pdf
ctl.content_pdf_url() to pass the PDF to the LLM.