Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agno.com/llms.txt

Use this file to discover all available pages before exploring further.

Classification is extraction where the schema is a closed set. Use a Literal for one label, a List[Literal] for many.
from typing import Literal

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from pydantic import BaseModel, Field


class Classification(BaseModel):
    label: Literal["positive", "negative", "neutral"] = Field(
        ..., description="The assigned sentiment label"
    )


agent = Agent(
    model=OpenAIResponses(id="gpt-5.5"),
    instructions="You classify product reviews by sentiment.",
    output_schema=Classification,
)

result = agent.run("It works as described, nothing special.").content
# Classification(label='neutral')
The Literal constrains the model to the closed set. There is no invalid label to clean up downstream.

Multi-label

A review can touch several aspects. Return any subset.
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"
    )

Hierarchical

For a taxonomy, return the path instead of a flat label.
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]

Span labeling

Asking the model to count characters is unreliable. Have it return the exact substring and locate offsets in Python.
from typing import List, Literal

from agno.agent import Agent
from agno.models.openai import OpenAIResponses
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=OpenAIResponses(id="gpt-5.5"),
    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))
The same shape drives PII redaction: detect the spans, then replace each with its tag in post-processing.

Choosing the shape

You needSchema
Exactly one labelLiteral[...]
Any subset of labelsList[Literal[...]]
A taxonomy pathA model with parent / child
Marked substringsA model with text + label, offsets in Python

Other modalities

Image, audio, video, and document classification follow the same schema pattern with a different input argument. See Multimodal inputs.

Next steps

TaskGuide
Extract fields instead of labelsStructured extraction
Score outputs against a rubricLLM as judge
Add reviewer agreementQuality pipeline

Developer Resources