Errors¶
Exception Hierarchy¶
TextAgentsError (base)
├── AgentDefinitionError
├── MissingInputError
├── InputTypeError
├── OutputValidationError
└── TemplateError
TextAgentsError
¶
Bases: Exception
Base exception for all TextAgents errors.
AgentDefinitionError
¶
Bases: TextAgentsError
Invalid agent definition file.
Raised when: - Missing required [agent] section - Missing model specification - No output_type fields defined - Invalid type specification - Unsupported type
missing_section
classmethod
¶
missing_section(section: str) -> AgentDefinitionError
Create error for missing required section.
Source code in src/textagents/errors.py
missing_field
classmethod
¶
missing_field(
section: str, field: str, example: str
) -> AgentDefinitionError
Create error for missing required field.
Source code in src/textagents/errors.py
no_output_fields
classmethod
¶
no_output_fields() -> AgentDefinitionError
Create error for empty output_type.
Source code in src/textagents/errors.py
unsupported_type
classmethod
¶
unsupported_type(
field_name: str, type_str: str, supported: Sequence[str]
) -> AgentDefinitionError
Create error for unsupported type.
Source code in src/textagents/errors.py
no_prompt_body
classmethod
¶
no_prompt_body() -> AgentDefinitionError
Create error for missing prompt body.
Source code in src/textagents/errors.py
no_placeholders
classmethod
¶
no_placeholders() -> AgentDefinitionError
Create error for prompt without placeholders.
Source code in src/textagents/errors.py
invalid_input_type
classmethod
¶
invalid_input_type(
input_name: str, type_str: str
) -> AgentDefinitionError
Create error for invalid input_type value.
Source code in src/textagents/errors.py
MissingInputError
¶
Bases: TextAgentsError
Required input not provided.
Raised when: - Required input variable not in run() kwargs - Input file (@ syntax) not found
missing_required
classmethod
¶
missing_required(
missing: Sequence[str],
provided: Sequence[str],
all_inputs: Sequence[str],
optional_placeholders: Sequence[str] | None = None,
) -> MissingInputError
Create error for missing required inputs.
Source code in src/textagents/errors.py
file_not_found
classmethod
¶
file_not_found(
input_name: str, file_path: str
) -> MissingInputError
Create error for missing input file.
Source code in src/textagents/errors.py
InputTypeError
¶
Bases: TextAgentsError
Input cannot be coerced to expected type.
Raised when: - String cannot be parsed to int/float/bool - Type mismatch for complex types
cannot_coerce
classmethod
¶
cannot_coerce(
input_name: str, value: object, target_type: str
) -> InputTypeError
Create error for type coercion failure.
Source code in src/textagents/errors.py
OutputValidationError
¶
Bases: TextAgentsError
Output validation failed after all retries.
Wraps the underlying PydanticAI validation error with context.
Source code in src/textagents/errors.py
TemplateError
¶
Bases: TextAgentsError
Template interpolation failed.
Raised when: - Placeholder in template not provided in inputs - Placeholder not in input_type and not a magic variable
missing_placeholder
classmethod
¶
missing_placeholder(
placeholder: str, available: Sequence[str]
) -> TemplateError
Create error for unresolved placeholder.
Source code in src/textagents/errors.py
Error Handling¶
import textagents
try:
agent = textagents.load_agent("agent.txt")
result = await agent.run()
except textagents.AgentDefinitionError:
print("Fix your agent file")
except textagents.MissingInputError as e:
print(f"Provide input: {e}")
except textagents.InputTypeError as e:
print(f"Fix input type: {e}")
except textagents.OutputValidationError:
print("LLM produced invalid output")
except textagents.TextAgentsError as e:
print(f"TextAgents error: {e}")