Skip to content

Errors in _ExtractUpdates don't propagate #68

@mokrueger

Description

@mokrueger

Hi,

i noticed that the errors in the _Extract class don't propagate through the invoke call. This means that if the patch extraction fails, there will not be a retry.

aka. this will not be triggered.

trustcall/trustcall/_base.py

Lines 1005 to 1014 in 8c7312b

except Exception as e:
return {
"messages": [
HumanMessage(
content="Fix the validation error while"
f" also avoiding: {repr(str(e))}"
)
],
"attempts": 1,
}

This is relevant if the llm does not generate the indices properly and applying the patch fails.

if target:
try:
patches = _ensure_patches(tc["args"])
if patches or self.tool_choice == "PatchDoc":
# The second condition is so that, when we are continuously
# updating a single doc, we will still include it in
# the output responses list; mainly for backwards
# compatibility
resolved_tool_calls.append(
ToolCall(
id=tc["id"],
name=tool_name,
args=_apply_patch(target, patches),
)
)
updated_docs[tc["id"]] = str(json_doc_id)
except Exception as e:
logger.error(f"Could not apply patch: {e}")
if rt:
rt.error = f"Could not apply patch: {repr(e)}"

We should re raise the error such that we can retry properly.
If you want I could draft a PR. Any input would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions