Async UiPath coded agent that downloads a Data Service file resource, performs extraction with the Documents service (Modern, IXP, or Pretrained with a document type), and optionally creates validation actions. It mirrors the structure and validation logic of the companion classification agent for consistent inputs/outputs.
- Python 3.12+ with the dependencies from
pyproject.toml(install viauv syncorpip install -e .). - UiPath cloud credentials available to the SDK (environment variables such as
UIPATH_CLIENT_ID,UIPATH_CLIENT_SECRET,UIPATH_SCOPE,UIPATH_URL, or an access token). - Access to the Data Service file resource and DU project (Modern/IXP/Pretrained with document type).
- Function:
main.py:main - Type: async; accepts
InputPydantic model or compatible dict.
file_resource(object, required): UiPath IResource descriptor for a Data Service file (IDrequired;FullName,MimeType,Metadataoptional).project_type(str):PRETRAINED,MODERN, orIXP(required unless reusing classification results).project_name(str, optional): Required forMODERN/IXPwhen not providing classification results.project_tag(str, optional): Required forMODERN/IXPwhen not providing classification results.document_type_name(str, optional): Required forMODERNandPRETRAINEDwhen not providing classification results.classification_results(list[ClassificationResult], optional): Reuse raw classification results directly.validate_classification(bool, defaultFalse): When true, fetch validated classification results instead of raw ones.validated_classification_action(ValidateClassificationAction, optional): Required whenvalidate_classificationis true; the agent will block until the action is completed and will reuse the validated results for extraction.validate_extraction(bool, defaultFalse): When true, create a validation action for extraction results.action_title,action_priority,action_catalog,action_folder,storage_bucket_name,storage_bucket_directory_path: Validation action settings (required whenvalidate_extractionis true).
All validation rules are enforced in Input.validate_settings to keep orchestrations simple.
project_type,project_name,project_tagdocument_type_id,document_idextraction_results: Raw extraction result dictionary.validation_action:ValidateExtractionActionwhen created.
- If
validate_classificationis true, the agent callsget_validate_classification_result_asyncwithvalidated_classification_actionand waits for completion, then uses the validated classification result. - If classification results are provided directly, they are reused; otherwise the file resource is downloaded and extracted using the provided project info.
- Optionally creates a validation action for the extraction output.
- Returns structured
Output.
import asyncio
from main import Input, main
payload = Input(
file_resource={
"ID": "<file resource UUID>",
"FullName": "Sample Invoice.pdf"
},
project_type="PRETRAINED",
document_type_name="Invoices"
)
result = asyncio.run(main(payload))
print(result.extraction_results)