Literal for one label, a List[Literal] for many.
Literal constrains the model to the closed set. There is no invalid label to clean up downstream.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Assign one label, a set of labels, a taxonomy path, or marked spans.
Literal for one label, a List[Literal] for many.
from typing import Literal
from agno.agent import Agent
from agno.models.google import Gemini
from pydantic import BaseModel, Field
class Classification(BaseModel):
label: Literal["positive", "negative", "neutral"] = Field(
..., description="The assigned sentiment label"
)
agent = Agent(
model=Gemini(id="gemini-3.5-flash"),
instructions="You classify product reviews by sentiment.",
output_schema=Classification,
)
result = agent.run("It works as described, nothing special.").content
# Classification(label='neutral')
Literal constrains the model to the closed set. There is no invalid label to clean up downstream.
from typing import List, Literal
from pydantic import BaseModel, Field
Aspect = Literal["food", "service", "value", "atmosphere", "cleanliness"]
class Tagging(BaseModel):
tags: List[Aspect] = Field(
..., description="Every aspect the reviewer commented on; empty if none"
)
from typing import List
from pydantic import BaseModel, Field
class HierarchicalTag(BaseModel):
parent: str = Field(..., description="Top-level category")
child: str = Field(..., description="Sub-category under the parent")
class Tagging(BaseModel):
tags: List[HierarchicalTag]
from typing import List, Literal
from agno.agent import Agent
from agno.models.google import Gemini
from pydantic import BaseModel, Field
class Entity(BaseModel):
text: str = Field(..., description="Exact substring from the input")
label: Literal["PERSON", "ORG", "LOCATION", "DATE"]
class Entities(BaseModel):
entities: List[Entity]
agent = Agent(
model=Gemini(id="gemini-3.5-flash"),
instructions=(
"Extract all named entities. Return the exact substring as it "
"appears, with its label. Do not paraphrase or normalize."
),
output_schema=Entities,
)
text = "On March 3rd, Sarah Johnson left Acme Corp to join Lumen Labs."
result = agent.run(text).content
for e in result.entities:
start = text.find(e.text)
print(e.label, e.text, start, start + len(e.text))
| You need | Schema |
|---|---|
| Exactly one label | Literal[...] |
| Any subset of labels | List[Literal[...]] |
| A taxonomy path | A model with parent / child |
| Marked substrings | A model with text + label, offsets in Python |
| Modality | Cookbook |
|---|---|
| Image | image_classification |
| Audio | audio_classification |
| Video | video_classification |
| Document | document_classification |
| Task | Guide |
|---|---|
| Extract fields instead of labels | Structured extraction |
| Score outputs against a rubric | LLM as judge |
| Add reviewer agreement | Quality pipeline |