From c5fb2398525f631e41b3a9e83d3310d6ee31576b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sat, 30 Mar 2024 16:42:12 -0300 Subject: [PATCH] Add validation for list items in records_to_text function --- src/backend/base/langflow/helpers/record.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/backend/base/langflow/helpers/record.py b/src/backend/base/langflow/helpers/record.py index d7b1d2b06..a64236d4f 100644 --- a/src/backend/base/langflow/helpers/record.py +++ b/src/backend/base/langflow/helpers/record.py @@ -29,6 +29,11 @@ def records_to_text(template: str, records: list[Record]) -> str: if isinstance(records, Record): records = [records] # Check if there are any format strings in the template + if any(not isinstance(record, Record) for record in records): + item_that_is_not_record = next((record for record in records if not isinstance(record, Record)), None) + raise ValueError( + f"All items in the list must be of type Record. Found: {item_that_is_not_record} of type {type(item_that_is_not_record)}." + ) formated_records = [template.format(data=record.data, **record.data) for record in records] return "\n".join(formated_records)