From 16ead7d5f30a532afabe2e6b3d6dabb0982c9871 Mon Sep 17 00:00:00 2001 From: ppanchigar Date: Wed, 4 Feb 2026 12:17:50 -0600 Subject: [PATCH 1/3] Fix date range processing: extract first range only, add JSON format instructions, increase max_tokens --- src/pipelines/saas/prompts/prompt_calls.py | 2 +- .../shared/extraction/one_to_n_funcs.py | 7 +++++++ src/prompts/prompt_templates.py | 18 ++++++++++++------ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/pipelines/saas/prompts/prompt_calls.py b/src/pipelines/saas/prompts/prompt_calls.py index 691a8b7..42e5a1a 100644 --- a/src/pipelines/saas/prompts/prompt_calls.py +++ b/src/pipelines/saas/prompts/prompt_calls.py @@ -899,7 +899,7 @@ def prompt_split_reimb_dates(date_range: str, filename: str) -> dict: prompt, model_id="sonnet_latest", filename=filename, - max_tokens=200, + max_tokens=500, cache=True, instruction=prompt_templates.SPLIT_REIMB_DATES_INSTRUCTION(), usage_label="SPLIT_REIMB_DATES", diff --git a/src/pipelines/shared/extraction/one_to_n_funcs.py b/src/pipelines/shared/extraction/one_to_n_funcs.py index f64a19a..81e1060 100644 --- a/src/pipelines/shared/extraction/one_to_n_funcs.py +++ b/src/pipelines/shared/extraction/one_to_n_funcs.py @@ -679,6 +679,13 @@ def split_reimb_dates(one_to_n_results: list, filename: str) -> list: llm_answer_final = prompt_calls.prompt_split_reimb_dates( date_range, filename ) + # Debug: print raw parsed LLM output + print(f"DEBUG split_reimb_dates - Index {index}:") + print(f" Input date_range: {date_range}") + print(f" Parsed LLM output: {llm_answer_final} (type: {type(llm_answer_final)})") + if isinstance(llm_answer_final, dict): + print(f" start_date: {llm_answer_final.get('start_date')}") + print(f" end_date: {llm_answer_final.get('end_date')}") # Update the specific record with parsed dates if llm_answer_final and isinstance(llm_answer_final, dict): if "start_date" in llm_answer_final: diff --git a/src/prompts/prompt_templates.py b/src/prompts/prompt_templates.py index afb0b48..6672304 100644 --- a/src/prompts/prompt_templates.py +++ b/src/prompts/prompt_templates.py @@ -2010,7 +2010,7 @@ def EFFECTIVE_DATE_FIX_PROMPT() -> Tuple[str, Callable[[str], dict]]: def SPLIT_REIMB_DATES_INSTRUCTION() -> str: """Static instruction for SPLIT_REIMB_DATES prompt caching.""" - return """[OBJECTIVE] + return f"""[OBJECTIVE] Extract start and end dates from a date range string and return them in YYYY/MM/DD format. [RULES] @@ -2034,17 +2034,23 @@ Extract start and end dates from a date range string and return them in YYYY/MM/ 5. If only one date is present: - Assume it is the start_date and set end_date as "N/A" -6. If no extractable dates are found in the text: +6. If multiple date ranges are present (separated by commas, e.g., "Effective 5/1/2018 - 4/30/2019, Effective 5/1/2019 - 4/30/2020"): + - Extract the FIRST (earliest) date range only + - Use the start_date from the first range and end_date from the first range + - Ignore all subsequent date ranges + +7. If no extractable dates are found in the text: - Return "N/A" for both start_date and end_date [OUTPUT FORMAT] -Return the dates in the following JSON format: -{ +Return ONLY the JSON dictionary with no explanatory text. Use the following format: +{{ "start_date": "YYYY/MM/DD", "end_date": "YYYY/MM/DD" -} +}} -Note: Use "N/A" for dates that cannot be determined or extracted from the input text.""" +Note: Use "N/A" for dates that cannot be determined or extracted from the input text. +{JSON_DICT_FORMAT_INSTRUCTIONS}""" def SPLIT_REIMB_DATES(date_range: str) -> Tuple[str, Callable[[str], dict]]: From 7ddd9dc192e4d406bf9afded979835fb344aa21b Mon Sep 17 00:00:00 2001 From: Katon Minhas Date: Wed, 4 Feb 2026 12:04:48 -0500 Subject: [PATCH 2/3] Fix prompt to ensure list-of-dicts-of-str --- src/prompts/prompt_templates.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/prompts/prompt_templates.py b/src/prompts/prompt_templates.py index 6672304..c20ca30 100644 --- a/src/prompts/prompt_templates.py +++ b/src/prompts/prompt_templates.py @@ -1442,17 +1442,20 @@ Examples: Briefly explain your reasoning. After your explanation, include the heading "FINAL PROVIDER INFO:" followed by a properly formatted JSON array with your final output. -[EXTRACTION AND FORMATTING INSTRUCTIONS] +[EXTRACTION INSTRUCTIONS] - First, analyze the text thoroughly and identify all provider entities - Return TIN and NPIs that are found on the page even if they aren't explicitly labeled as such. - If the table contains multiple name columns (e.g. 'System Name' and 'Facility Name'), YOU MUST extract the specific 'Facility Name' or 'Hospital Name' column. - IMPORTANT VALIDATION REQUIREMENTS: * TIN must be exactly 9 digits (no more, no less) * NPI must be exactly 10 digits (no more, no less) - * Double-check the digit count for each TIN and NPI before including them in the response -- In your response, include ONLY ONE SINGLE properly formatted JSON array, after your explanation -- Each provider must be an object within this array + * CAREFULLY double-check the digit count for each TIN and NPI before including them in the response + +[FORMATTING INSTRUCTIONS] +- In your response, include ONLY ONE SINGLE properly formatted JSON List-of-Dicts-of-Str, after your explanation +- Each provider must be an object (DICT) within this array - All provider objects must have these exact keys: "TIN", "NPI", "NAME" +- ALl dict values must be strings - if there are multiple different TINs or NPIs for an identical NAME, put them in different dictionaries. - Use "N/A" for any missing values - A provider record is considered valid as long as either a TIN, NPI, or NAME is present. If any one or two of those fields are missing, use "N/A" for those fields. - Your final JSON array must begin with an opening bracket '[' and end with a closing bracket ']' @@ -1467,13 +1470,18 @@ FINAL PROVIDER INFO: "NPI": "1234567890", "NAME": "Main Provider Group" }, + { + "TIN": "124681012", + "NPI": "N/A", + "NAME": "Main Provider Group" + }, { "TIN": "987654321", - "NPI": null, + "NPI": "N/A, "NAME": "Dr. John Smith", }, { - "TIN": null, + "TIN": "N/A", "NPI": "1234567890", "NAME": "Jane Doe, CRNA" } From a1e28f94ee4eaaf4d26d8856adaa91bb1aef3c60 Mon Sep 17 00:00:00 2001 From: Katon Minhas Date: Wed, 4 Feb 2026 12:05:25 -0500 Subject: [PATCH 3/3] file_processing --- src/pipelines/saas/file_processing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pipelines/saas/file_processing.py b/src/pipelines/saas/file_processing.py index 9628810..e44b07f 100644 --- a/src/pipelines/saas/file_processing.py +++ b/src/pipelines/saas/file_processing.py @@ -258,7 +258,6 @@ def run_one_to_one_prompts( ################## Fill NA Mapping ################## one_to_one_results = aarete_derived.fill_na_mapping(one_to_one_results) - print("After all one_to_one: ", one_to_one_results) return one_to_one_results[0]