Process Text

The ProcessText action allows you to process unstructured text using Large Language Models (LLMs) according to provided instructions. The output is a structured object based on a Pydantic model you define.

Action

class aiviro.actions.documents.ProcessText(instructions: str, output_model: type[BaseModel], text: str, examples: Sequence[tuple[str, BaseModel]] | None = None)

Process text using Large Language Model (LLM) according to the provided instructions.

This action takes an unstructured text and a set of instructions for an LLM to process the text. The output is a structured object based on the provided output model, using Pydantic model.

Parameters:
  • robot – Robot instance to use for processing the text

  • instructions – Detailed instructions for the LLM to process the text

  • output_model – Pydantic model to use for the output

  • text – Text to process

  • examples – Optional list of input and corresponding output examples

Returns:

ProcessTextResponse object containing the JSON formatted response from the LLM model.

Example:

>>> from aiviro.actions.documents import ProcessText
>>> from pydantic import BaseModel
>>>
>>> class Person(BaseModel):
...     name: str
...     age: int
...
>>> robot = ...  # e.g.: create_desktop_robot()
>>> process_text = ProcessText(
...     instructions="Extract name and age from the text.",
...     output_model=Person,
...     text="John is 30 years old.",
... )
>>> result = process_text(robot=robot)
>>>
>>> # convert response to the Person object
>>> person = Person.model_validate(result.response_dict)
>>> # access the extracted data
>>> print(person.name)
>>> print(person.age)

Data Schemas

The action returns a ProcessTextResponse object with:

  • response: JSON string containing the structured output

  • response_json: Parsed JSON as a dictionary

  • model_usage: Optional LLM usage statistics

Note

Always use result.response_json to access the parsed data, then validate it with your Pydantic model using YourModel.model_validate(result.response_json).

pydantic model aiviro.core.utils.api_client.schemas.process_text.ProcessTextResponse
field model_usage: LLMUsage | None = None
field response: str [Required]

Response from the LLM model in JSON format.

property response_dict: dict