Unstructured Text

The ProcessText action allows you to process unstructured text using Large Language Models (LLMs) according to provided instructions. The output is a JSON-like string or object that can be validated against a provided Pydantic model.

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:
  • 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

pydantic model aiviro.core.utils.api_client.schemas.process_text.ProcessTextResponse

Response from the ProcessText action.

Note

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

field model_usage: LLMUsage | None = None

Optional usage statistics of the LLM model.

field response: str [Required]

Response from the LLM model in JSON-like string.

property response_dict: dict

Parsed JSON response as a dictionary