Compare commits

...

3 Commits

Author SHA1 Message Date
pjames27 7f9d11f234 Removing redundant job id; maintain NO_DATA_FOUND_IN_FILE throw behavior 2025-10-23 13:28:12 -07:00
pjames27 3dbddc999e Changeset patch notes 2025-10-23 12:23:44 -07:00
pjames27 3a31e8a10a Return partial result on failed job 2025-10-23 12:06:16 -07:00
3 changed files with 45 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llama-cloud-services-py": patch
---
Now return partial results on job failure
+33 -3
View File
@@ -1146,6 +1146,25 @@ class LlamaParse(BasePydanticReader):
)
current_interval = self._calculate_backoff(current_interval)
async def _get_job_result_with_error_handling(
self, job_id: str, result_type: str, verbose: bool = False
) -> Dict[str, Any]:
"""Get job result with error handling based on ignore_errors setting."""
try:
return await self._get_job_result(job_id, result_type, verbose=verbose)
except JobFailedException as e:
if self.ignore_errors:
# Return error information when ignore_errors is True
return {
"pages": [],
"job_metadata": {},
"error": f"{e.status}: {e.error_message or 'No error message'}",
"error_code": e.error_code,
"status": e.status,
}
else:
raise e
async def _parse_one(
self,
file_path: FileInput,
@@ -1187,7 +1206,7 @@ class LlamaParse(BasePydanticReader):
)
if self.verbose:
print("Started parsing the file under job_id %s" % job_id)
result = await self._get_job_result(
result = await self._get_job_result_with_error_handling(
job_id, result_type or self.result_type.value, verbose=self.verbose
)
return job_id, result
@@ -1250,6 +1269,15 @@ class LlamaParse(BasePydanticReader):
result_type=ResultType.JSON.value,
partition_target_pages=f"{total}-{total + size - 1}",
)
# Check if the result is an error result (when ignore_errors=True)
if json_result.get("error_code") == "NO_DATA_FOUND_IN_FILE":
raise JobFailedException(
job_id=job_id,
status=json_result.get("status", "ERROR"),
error_code=json_result.get("error_code"),
error_message=json_result.get("error"),
)
result_type = result_type or self.result_type.value
if result_type == ResultType.JSON.value:
job_result = json_result
@@ -1775,7 +1803,7 @@ class LlamaParse(BasePydanticReader):
JobResult object or list of JobResult objects if multiple job IDs were provided.
"""
if isinstance(job_id, str):
result = await self._get_job_result(
result = await self._get_job_result_with_error_handling(
job_id, ResultType.JSON.value, verbose=self.verbose
)
return JobResult(
@@ -1790,7 +1818,9 @@ class LlamaParse(BasePydanticReader):
elif isinstance(job_id, list):
results = []
jobs = [
self._get_job_result(id_, ResultType.JSON.value, verbose=self.verbose)
self._get_job_result_with_error_handling(
id_, ResultType.JSON.value, verbose=self.verbose
)
for id_ in job_id
]
results = await run_jobs(
+7
View File
@@ -269,6 +269,13 @@ class JobResult(SafeBaseModel):
error: Optional[str] = Field(
default=None, description="The error message if the job failed."
)
error_code: Optional[str] = Field(
default=None, description="The error code if the job failed."
)
status: Optional[str] = Field(
default=None,
description="The job status (e.g., PENDING, SUCCESS, ERROR, CANCELED).",
)
def __init__(
self,