@task
Overview
The @task decorator creates a child span for a single unit of work — an LLM call, data processing step, validation, or any discrete operation within a workflow.
Parameters
Function usage
Class usage
Features
- Automatic I/O capture — Function arguments and return values are serialized as span input/output (up to 1MB).
- Exception recording — Exceptions are automatically recorded on the span with error status.
- Async support — Works with
async deffunctions and generators.
Best practices
- Keep tasks small and focused on a single operation
- Use task names that reflect intent, not implementation details
- Nest tasks inside workflows for proper trace hierarchy