From 6902b8b4dd39107251872b9bacb176cd7bd2a73d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Tue, 30 Jan 2024 17:36:14 +0100 Subject: [PATCH] fix: Inform the LLM when the claim update is invalid --- main.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index f04903b4..d0f4ad84 100644 --- a/main.py +++ b/main.py @@ -942,12 +942,10 @@ def _error_response() -> Tuple[CallModel, ActionModel]: content = f'Failed to update a non-editable field "{parameters['field']}".' else: try: - # Define the field - setattr( - call.claim, parameters["field"], parameters["value"] - ) - # Trigger a re-validation to spot errors before saving - ClaimModel.model_validate(call.claim) + # Define the field and force to trigger validation + copy = call.claim.model_dump() + copy[parameters["field"]] = parameters["value"] + call.claim = ClaimModel.model_validate(copy) except ValidationError as e: content = f'Failed to edit field "{parameters["field"]}": {e.json()}' if not content: