mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-18 21:21:05 +02:00
fix: return actionable error for malformed page ranges in local tool
The local get_page_content agent tool only converted DocumentNotFoundError
into a JSON error; a malformed page spec ("all", "5-") let parse_pages'
ValueError surface as the agent SDK's generic non-fatal tool-failure text
("An error occurred... invalid literal for int()"), which the model can't
act on. Catch (ValueError, AttributeError) and return the same actionable
"Invalid pages format: ... Use '5-7', '3,8', or '12'" message the legacy
retrieval tool already gives, so the model can retry with a valid range.
This commit is contained in:
parent
91e016d2e4
commit
56fc3bf7bb
2 changed files with 20 additions and 0 deletions
|
|
@ -306,6 +306,14 @@ class LocalBackend:
|
|||
result = backend.get_page_content(col_name, doc_id, pages)
|
||||
except DocumentNotFoundError:
|
||||
return json.dumps({"error": f"doc_id '{doc_id}' not found."})
|
||||
except (ValueError, AttributeError) as e:
|
||||
# A malformed page spec ("all", "5-") is a recoverable bad tool
|
||||
# argument: hand the model an actionable error it can correct
|
||||
# (mirroring the legacy retrieval tool) rather than letting the
|
||||
# ValueError surface as the agent SDK's generic tool-failure text.
|
||||
return json.dumps({
|
||||
"error": f"Invalid pages format: {pages!r}. Use '5-7', '3,8', or '12'. Error: {e}"
|
||||
})
|
||||
return json.dumps(result, ensure_ascii=False)
|
||||
|
||||
tools = [get_document, get_document_structure, get_page_content]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue