Fix REIMB_TERM being converted to list in lesser_of_distribution

- Fixed prompt_lesser_of_distribution to extract string from list when parser returns list
- Added debug print statements to trace REIMB_TERM format through processing pipeline
- Removed defensive normalization checks that are no longer needed upstream
- Added debug output in reimbursement_level and methodology_breakout_single_row to track data flow
This commit is contained in:
ppanchigar
2026-02-03 17:15:14 -06:00
parent 4c0d2930d5
commit a633f67c62
10 changed files with 343 additions and 72 deletions
@@ -32,18 +32,26 @@ def fill_na_mapping(answer_dicts):
all_lob_values = set()
# Get existing AARETE_DERIVED_LOB values (if any)
# Handle both list and string formats (JSON lists or pipe-delimited strings)
existing_lob_list = answer_dict.get("AARETE_DERIVED_LOB", "")
if not string_utils.is_empty(existing_lob_list):
for lob_val in existing_lob_list:
# Normalize to list format
if isinstance(existing_lob_list, list):
lob_items = existing_lob_list
elif isinstance(existing_lob_list, str):
# Handle pipe-delimited format (backward compatibility)
if "|" in existing_lob_list:
all_lob_values.update(
v.strip()
for v in lob_val.split("|")
if v.strip() and v.strip() != "N/A"
)
elif lob_val.strip() and lob_val.strip() != "N/A":
all_lob_values.add(lob_val)
lob_items = [v.strip() for v in existing_lob_list.split("|")]
else:
lob_items = [existing_lob_list]
else:
lob_items = [str(existing_lob_list)]
# Process each LOB value
for lob_val in lob_items:
if isinstance(lob_val, str) and lob_val.strip() and lob_val.strip() != "N/A":
all_lob_values.add(lob_val.strip())
# Get AARETE_DERIVED_LOB from AARETE_DERIVED_PROGRAM crosswalk (always check if PROGRAM exists)
program_lob_values = set()
@@ -58,16 +66,24 @@ def fill_na_mapping(answer_dicts):
not string_utils.is_empty(program_filled_value_list)
and "N/A" not in program_filled_value_list
):
for program_lob_val in program_filled_value_list:
if "|" in program_lob_val:
program_lob_values = set(
v.strip()
for v in program_lob_val.split("|")
if v.strip() and v.strip() != "N/A"
)
elif program_lob_val.strip() and program_lob_val.strip() != "N/A":
program_lob_values = {program_lob_val.strip()}
all_lob_values.update(program_lob_values)
# Normalize to list format (handle both list and string)
if isinstance(program_filled_value_list, list):
program_lob_items = program_filled_value_list
elif isinstance(program_filled_value_list, str):
# Handle pipe-delimited format (backward compatibility)
if "|" in program_filled_value_list:
program_lob_items = [v.strip() for v in program_filled_value_list.split("|")]
else:
program_lob_items = [program_filled_value_list]
else:
program_lob_items = [str(program_filled_value_list)]
# Process each program LOB value
for program_lob_val in program_lob_items:
if isinstance(program_lob_val, str) and program_lob_val.strip() and program_lob_val.strip() != "N/A":
program_lob_values.add(program_lob_val.strip())
# Update all_lob_values after processing all program LOB values
all_lob_values.update(program_lob_values)
# Get AARETE_DERIVED_LOB from PRODUCT crosswalk (always check if PRODUCT exists)
product_lob_values = set()
@@ -82,16 +98,24 @@ def fill_na_mapping(answer_dicts):
not string_utils.is_empty(product_filled_value_list)
and "N/A" not in product_filled_value_list
):
for product_lob_val in product_filled_value_list:
if "|" in product_lob_val:
product_lob_values = set(
v.strip()
for v in product_filled_value_list.split("|")
if v.strip() and v.strip() != "N/A"
)
elif product_lob_val.strip() and product_lob_val.strip() != "N/A":
product_lob_values = {product_lob_val.strip()}
all_lob_values.update(product_lob_values)
# Normalize to list format (handle both list and string)
if isinstance(product_filled_value_list, list):
product_lob_items = product_filled_value_list
elif isinstance(product_filled_value_list, str):
# Handle pipe-delimited format (backward compatibility)
if "|" in product_filled_value_list:
product_lob_items = [v.strip() for v in product_filled_value_list.split("|")]
else:
product_lob_items = [product_filled_value_list]
else:
product_lob_items = [str(product_filled_value_list)]
# Process each product LOB value
for product_lob_val in product_lob_items:
if isinstance(product_lob_val, str) and product_lob_val.strip() and product_lob_val.strip() != "N/A":
product_lob_values.add(product_lob_val.strip())
# Update all_lob_values after processing all product LOB values
all_lob_values.update(product_lob_values)
# Set the merged, deduplicated value
if all_lob_values:
@@ -165,11 +189,16 @@ def get_crosswalk_fields(answer_dicts: list, constants: Constants):
if "AARETE_DERIVED" in to_field_name:
to_field_answer_list.append(individual_from_field_value)
else:
to_field_answer_list.append(
crosswalk.create_reverse_mapping().get(
individual_from_field_value
)
)
# Reverse mapping returns dict[str, list[str]], so .get() returns a list
# We need to extend, not append, to avoid nested lists
reverse_mapping = crosswalk.create_reverse_mapping()
reverse_result = reverse_mapping.get(individual_from_field_value)
if reverse_result is not None:
# reverse_result is a list, extend it
to_field_answer_list.extend(reverse_result)
else:
# If not found in reverse mapping, keep original value
to_field_answer_list.append(individual_from_field_value)
answer_dict[to_field_name] = to_field_answer_list
# update from field value to list if not already
if not isinstance(from_field_value, list):