unitxt.error_utils module

class unitxt.error_utils.Documentation[source]

Bases: object

exception unitxt.error_utils.UnitxtError(message: str, additional_info_id: str | None = None)[source]

Bases: Exception

Exception raised for Unitxt errors.

Parameters:
  • message (str) – explanation of the error

  • additional_info_id (Optional[str]) – relative path to additional documentation on web If set, should be one of the DOCUMENTATION_* constants in the error_utils.py file.

class unitxt.error_utils.UnitxtWarning(message: str, additional_info_id: str | None = None)[source]

Bases: object

Object to format warning message to log.

Parameters:
  • message (str) – explanation of the warning

  • additional_info_id (Optional[str]) – relative path to additional documentation on web If set, should be one of the DOCUMENTATION_* constants in the error_utils.py file.

unitxt.error_utils.additional_info(path: str) str[source]
unitxt.error_utils.error_context(context_object: Any = None, **context)[source]

Context manager that catches exceptions and re-raises them with additional context.

Parameters:
  • context_object – The object being processed (optional)

  • **context

    Any additional context to include in the error message. You can provide any key-value pairs that help identify where the error occurred.

    Special context keys: - help: Documentation links to help with the error.

    Can be a string (single URL), dict (label: URL), or list of URLs/dicts.

Examples

with error_context(self, operation=”validation”, item_id=42):

result = process_item(item)

with error_context(operation=”schema_validation”, help=”https://docs.example.com/schema”):

validate_schema(data)

with error_context(processor, step=”preprocessing”, batch_size=32):

results = process_batch(batch)