Merged in chore/update_effective_date_prompts_and_keywords (pull request #329)
modified keywords and prompts for effective date * modified keywords and prompts for effective date Approved-by: Alex Galarce
This commit is contained in:
committed by
Alex Galarce
parent
1d49a7f9b1
commit
b094542cbe
@@ -6,28 +6,105 @@ regex_backticks = r"\|([^|]+)\|"
|
||||
#TODO: leave this one in here; don't move it to prompts until we get confirmation that we want to handle meridian differently.
|
||||
def get_effective_date_meridian_prompt(context):
|
||||
prompt_template = f""""
|
||||
Please analyze the following contract and extract ONLY the Signature Date. Follow these precise rules in order:
|
||||
Please analyze the following contract and extract ONLY the Signature Date. FOLLOW these precise rules in order:
|
||||
|
||||
1. Look for Signature Date
|
||||
1. LOOK FOR SIGNATURE DATE:
|
||||
- FIND dates near signature sections, signature lines, or signature blocks
|
||||
- CHECK for dates beside, above, or below signature lines
|
||||
|
||||
2. IF MULTIPLE matches are found:
|
||||
- CHECK that each date is CLEARLY associated with signatures
|
||||
- PRIORITIZE the LATEST FULL DATE
|
||||
- DO NOT include dates from non-signature sections
|
||||
|
||||
3. DATE FORMAT HANDLING RULES:
|
||||
[A] ANALYZE THE DATE:
|
||||
- IF already in YYYY-MM-DD format → KEEP IT
|
||||
- IF in another format → PROCEED TO [B]
|
||||
|
||||
[B] CHECK FOR FORMAT CERTAINTY:
|
||||
ONLY proceed with conversion if either:
|
||||
a) Format is UNAMBIGIOUS and COMPREHENDABLE in the document
|
||||
b) Date has WRITTEN MONTHS making format unambiguous ("January 1, 2024")
|
||||
c) Date format is SELF-EVIDENT and LOGICALLY UNAMBIGUOUS meaning:
|
||||
- Numbers MUST make it IMPOSSIBLE to interpret in any other way
|
||||
- There can be NO OTHER POSSIBLE valid date interpretation
|
||||
- Examples:
|
||||
* "13/05/2024" where 13 can ONLY be a day as it's impossible for it to be a month
|
||||
* "15 June 12" where given modern context, this MUST be June 15, 2012
|
||||
|
||||
[C] YEAR HANDLING RULES:
|
||||
PRIMARY STEP - ANALYZE YEAR DIGITS:
|
||||
• WHEN ENCOUNTERING SHORT/INCOMPLETE YEARS:
|
||||
|
||||
2. If multiple matches are found:
|
||||
- Prioritize the latest full date
|
||||
DETECTION PHASE:
|
||||
▸ CHECK NEARBY DATES:
|
||||
- LOOK for ALL dates near the target date
|
||||
- IF ALL nearby dates show SAME year (e.g., all 2020):
|
||||
* USE that year for completion
|
||||
* Example: "July 1ST 20" near "June 15 2020" and "May 20 2020" → complete as 2020
|
||||
- IF ALL nearby years are NOT SAME:
|
||||
* KEEP original format
|
||||
* DO NOT attempt completion
|
||||
|
||||
3. If only partial dates are found, return N/A.
|
||||
|
||||
4. Return the date in YYYY-MM-DD format or N/A if date not found. Enclose just your final answer in |pipes|.
|
||||
|
||||
Here is the contract to analyze:
|
||||
|
||||
## START CONTRACT TEXT ##
|
||||
|
||||
{context}
|
||||
ACTION PHASE:
|
||||
▸ FOR CONFIRMED LAST TWO DIGITS:
|
||||
- Single digit (0-9): ADD "200" prefix (e.g., "9" → "2009")
|
||||
- Two digits (00-49): ADD "20" prefix (e.g., "12" → "2012")
|
||||
- Two digits (50-99): ADD "19" prefix (e.g., "95" → "1995")
|
||||
|
||||
## END CONTRACT TEXT ##
|
||||
▸ FOR CONFIRMED FIRST TWO DIGITS:
|
||||
COMPLETE ONLY IF:
|
||||
- Nearby dates CONSISTENTLY show same year
|
||||
- Example: "15 June, 20__" near several 2020 dates → complete as "2020"
|
||||
|
||||
▸ IF POSITION UNCLEAR or NO CONSISTENT YEAR PATTERN:
|
||||
- KEEP original format
|
||||
- NO completion attempt
|
||||
|
||||
Before returning the output, VERIFY the date format is YYYY-MM-DD. If the date is not found, return N/A.
|
||||
VALIDATION:
|
||||
• ONLY apply these rules when:
|
||||
- Format certainty criteria met
|
||||
- Evidence is logically undeniable
|
||||
- No other interpretation possible
|
||||
|
||||
Finally state "Answer: |YYYY-MM-DD| or |N/A|"
|
||||
[D] MAKE FORMAT DECISION:
|
||||
IF ANY condition from [B] is met AND there is NO POSSIBLE ambiguity:
|
||||
- CONVERT to YYYY-MM-DD format
|
||||
- APPLY year rules from [C] if needed
|
||||
|
||||
IN ALL OTHER CASES:
|
||||
- KEEP the date in its ORIGINAL format exactly as found
|
||||
- DO NOT attempt conversion
|
||||
- DO NOT infer format from patterns or other dates
|
||||
|
||||
4. IF NO valid signature date found:
|
||||
- The answer MUST BE N/A
|
||||
|
||||
5. Before providing the final answer, SHOW your reasoning:
|
||||
- LIST ALL signature dates found that MATCH Rule #1
|
||||
- For EACH date found, EXPLAIN:
|
||||
* WHERE it was found (specific signature context)
|
||||
* WHY it is being CONSIDERED or EXCLUDED
|
||||
- IF converting to YYYY-MM-DD format:
|
||||
* EXPLAIN why you are EXTREMELY CONFIDENT about the format
|
||||
* SHOW your conversion work
|
||||
* JUSTIFY any year prefix assumptions
|
||||
- IF keeping original format:
|
||||
* EXPLAIN why conversion wasn't possible
|
||||
* CONFIRM the date is complete and valid
|
||||
- EXPLAIN your final date selection or why N/A is being returned
|
||||
|
||||
6. ENCLOSE just your final answer in |pipes|.
|
||||
|
||||
Here is the contract to analyze:
|
||||
## START CONTRACT TEXT ##
|
||||
|
||||
{context}
|
||||
|
||||
## END CONTRACT TEXT ##
|
||||
|
||||
Finally state "Answer: |YYYY-MM-DD| or |Original Date Format| or |N/A|"
|
||||
"""
|
||||
|
||||
return prompt_template
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
# "irs_group / "Gray Group":"
|
||||
# 'Tax ID,TIN,IRS,Provider Name,National Provider Identifier,NPI,Other NPIs,To Provider At:,To Provider at:'
|
||||
|
||||
import config
|
||||
|
||||
GROUPED_KEYWORD_MAPPINGS = {
|
||||
"term_group": {
|
||||
"fields": [
|
||||
@@ -98,7 +100,9 @@ GROUPED_KEYWORD_MAPPINGS = {
|
||||
"CONTRACT_EFFECTIVE_DT": {
|
||||
"fields": ["CONTRACT_EFFECTIVE_DT"],
|
||||
"methodology": "include_exclude",
|
||||
"included_keywords" : ["Effective Date", "entered into", "shall be effective", "will become effective"],
|
||||
"included_keywords" : ["Effective Date", "entered into", "shall be effective", "will become effective", "dated this", "made and entered into", "made this", "dated and effective"] \
|
||||
if any([cand in config.BATCH_ID.lower() for cand in ["cnc-4","cnc-4a","cnc-4b"]]) \
|
||||
else ["Effective Date", "entered into", "shall be effective", "will become effective"],
|
||||
"excluded_keywords" : ["Permit","Registration","Department of Public Health"],
|
||||
"case_sensitive": False,
|
||||
},
|
||||
|
||||
+114
-33
@@ -1,4 +1,5 @@
|
||||
import valid
|
||||
import config
|
||||
|
||||
#####################################################################################
|
||||
##################################### BOTTOM UP #####################################
|
||||
@@ -395,52 +396,132 @@ If for any question, no correct answer is found, return 'N/A'.
|
||||
{questions}.
|
||||
"""
|
||||
|
||||
def get_effective_date_prompt(context: str) -> str:
|
||||
"""
|
||||
Generate a prompt template to extract the effective date from a contract.
|
||||
|
||||
Args:
|
||||
context (str): The contract text to analyze.
|
||||
|
||||
Returns:
|
||||
str: The prompt template for extracting the effective date.
|
||||
def get_effective_date_prompt(context):
|
||||
batch_4_keywords = """
|
||||
- "dated this" FOLLOWED BY a date
|
||||
- "made and entered into" FOLLOWED BY a date
|
||||
- "made this" FOLLOWED BY a date
|
||||
- "dated and effective" FOLLOWED BY a date
|
||||
"""
|
||||
batch_4_keywords = batch_4_keywords if any([cand in config.BATCH_ID.lower() for cand in ["cnc-4","cnc-4a","cnc-4b"]]) else ""
|
||||
|
||||
prompt_template = f"""
|
||||
Please analyze the following contract and extract ONLY the effective date of the contract or amendment. Follow these precise rules in order:
|
||||
Please analyze the following contract and extract ONLY the effective date of the contract or amendment. THE DATE MAY OR MAY NOT BE EXPLICITLY LABELED AS AN EFFECTIVE DATE. FOLLOW these precise rules in order:
|
||||
|
||||
1. Look for dates that appear after phrases matching these exact patterns:
|
||||
- "Effective Date:" followed by a date
|
||||
- "FOR HEALTH PLAN USE ONLY" section containing "Effective Date:"
|
||||
- "To be completed by Health Plan only:" section containing "Effective Date:"
|
||||
- "is entered into as of" followed by a date
|
||||
1. LOOK FOR dates using the following guidelines:
|
||||
a) LOOK FOR dates that appear after these common phrases but not limited to (case-insensitive matching):
|
||||
- "Effective Date:" FOLLOWED BY a date
|
||||
- "FOR HEALTH PLAN USE ONLY" section CONTAINING "Effective Date:"
|
||||
- "To be completed by Health Plan only:" section CONTAINING "Effective Date:"
|
||||
- "is entered into as of" FOLLOWED BY a date
|
||||
- "effective as of" FOLLOWED BY a date
|
||||
- "shall begin on" FOLLOWED BY a date
|
||||
- "Effective Date of Agreement:" FOLLOWED BY a date
|
||||
- "Effective Date of Amendment" FOLLOWED BY a date
|
||||
{batch_4_keywords}
|
||||
|
||||
b) ALSO LOOK FOR dates in phrases that SEMANTICALLY INDICATE an effective date, even if they DO NOT EXACTLY MATCH the phrases above. Examples include but ARE NOT LIMITED TO:
|
||||
- Phrases indicating when an contract or amendment begins or takes effect
|
||||
- Phrases specifying the start date of the contract or amendment
|
||||
- Phrases defining when the contract or amendment becomes operational
|
||||
- ANY other phrasing that CLEARLY INDICATES the date when the contract or amendment becomes effective
|
||||
|
||||
2. If multiple matches are found:
|
||||
- Prioritize dates within "FOR HEALTH PLAN USE ONLY" or "To be completed by Health Plan only" sections
|
||||
- Then prioritize dates that directly follow "Effective Date:"
|
||||
2. DO NOT INCLUDE the date found in the Signature Date section:
|
||||
- IF AND ONLY IF there is NO MENTION of that date being the effective date
|
||||
|
||||
3. Do not use the date found in the "Signature Date" section.
|
||||
- If there is nothing next to "Effective Date:", return N/A.
|
||||
- If there is only one date in the document, don't extract this date unless it is explicitly labeled "effective date". It is okay to return N/A.
|
||||
3. IF MULTIPLE matches are found:
|
||||
- VERIFY that you have PRECISELY followed RULE #1 and RULE #2
|
||||
- EVERY SINGLE DATE in the MULTIPLE matches MUST STRICTLY follow RULE #1 and RULE #2
|
||||
- PRIORITIZE the LATEST date
|
||||
|
||||
4. If partial dates are found, return N/A.
|
||||
4. DATE FORMAT HANDLING RULES:
|
||||
PRIMARY GOAL: Convert date to YYYY-MM-DD format in specific cases only
|
||||
|
||||
DECISION FLOW:
|
||||
[A] ANALYZE THE DATE:
|
||||
- IF already in YYYY-MM-DD format → KEEP IT
|
||||
- IF in another format → PROCEED TO [B]
|
||||
|
||||
[B] CHECK FOR FORMAT CERTAINTY:
|
||||
ONLY proceed with conversion if either:
|
||||
a) Format is UNAMBIGIOUS and COMPREHENDABLE in the document
|
||||
b) Date has WRITTEN MONTHS making format unambiguous ("January 1, 2024")
|
||||
c) Date format is SELF-EVIDENT and LOGICALLY UNAMBIGUOUS meaning:
|
||||
- Numbers MUST make it IMPOSSIBLE to interpret in any other way
|
||||
- There can be NO OTHER POSSIBLE valid date interpretation
|
||||
- Examples:
|
||||
* "13/05/2024" where 13 can ONLY be a day as it's impossible for it to be a month
|
||||
* "15 June 12" where given modern context, this MUST be June 15, 2012
|
||||
|
||||
5. Return the date in YYYY-MM-DD format or N/A if date not found. Enclose just your final answer in |pipes|.
|
||||
|
||||
Here is the contract to analyze:
|
||||
|
||||
## START CONTRACT TEXT ##
|
||||
|
||||
{context}
|
||||
[C] YEAR HANDLING RULES:
|
||||
PRIMARY STEP - ANALYZE YEAR DIGITS:
|
||||
• WHEN ENCOUNTERING SHORT/INCOMPLETE YEARS:
|
||||
|
||||
## END CONTRACT TEXT ##
|
||||
DETECTION PHASE:
|
||||
▸ CHECK NEARBY DATES:
|
||||
- LOOK for ALL dates near the target date
|
||||
- IF ALL nearby dates show SAME year (e.g., all 2020):
|
||||
* USE that year for completion
|
||||
* Example: "July 1ST 20" near "June 15 2020" and "May 20 2020" → complete as 2020
|
||||
- IF ALL nearby years are NOT SAME:
|
||||
* KEEP original format
|
||||
* DO NOT attempt completion
|
||||
|
||||
Ensure that you do not use the date found in the "Signature Date" section.
|
||||
ACTION PHASE:
|
||||
▸ FOR CONFIRMED LAST TWO DIGITS:
|
||||
- Single digit (0-9): ADD "200" prefix (e.g., "9" → "2009")
|
||||
- Two digits (00-49): ADD "20" prefix (e.g., "12" → "2012")
|
||||
- Two digits (50-99): ADD "19" prefix (e.g., "95" → "1995")
|
||||
|
||||
▸ FOR CONFIRMED FIRST TWO DIGITS:
|
||||
COMPLETE ONLY IF:
|
||||
- Nearby dates CONSISTENTLY show same year
|
||||
- Example: "15 June, 20__" near several 2020 dates → complete as "2020"
|
||||
|
||||
▸ IF POSITION UNCLEAR or NO CONSISTENT YEAR PATTERN:
|
||||
- KEEP original format
|
||||
- NO completion attempt
|
||||
|
||||
Before returning the output, VERIFY the date format is YYYY-MM-DD. If the date is not found, return N/A.
|
||||
VALIDATION:
|
||||
• ONLY apply these rules when:
|
||||
- Format certainty criteria met
|
||||
- Evidence is logically undeniable
|
||||
- No other interpretation possible
|
||||
|
||||
[D] MAKE FORMAT DECISION:
|
||||
IF ANY condition from [B] is met AND there is NO POSSIBLE ambiguity:
|
||||
- CONVERT to YYYY-MM-DD format
|
||||
- APPLY year rules from [C] if needed
|
||||
|
||||
IN ALL OTHER CASES:
|
||||
- KEEP the date in its ORIGINAL format exactly as found
|
||||
- DO NOT attempt conversion
|
||||
- DO NOT infer format from patterns or other dates in document
|
||||
|
||||
Finally state "Answer: |YYYY-MM-DD| or |N/A|"
|
||||
5. IF NO valid date is found:
|
||||
- The answer MUST BE N/A
|
||||
|
||||
6. Before providing the final answer, SHOW your reasoning:
|
||||
- LIST ALL dates found that MATCH patterns in RULE #1
|
||||
- For EACH date found:
|
||||
* EXPLAIN why it's considered for effective date or not
|
||||
* IF dealing with partial year, SHOW nearby dates found
|
||||
* EXPLAIN if nearby dates show consistent year pattern
|
||||
- IF converting to YYYY-MM-DD format, EXPLAIN your confidence in the conversion
|
||||
- JUSTIFY your final date selection or why N/A is being returned
|
||||
|
||||
7. ENCLOSE just your final answer in |pipes|.
|
||||
|
||||
Here is the contract to analyze:
|
||||
## START CONTRACT TEXT ##
|
||||
|
||||
{context}
|
||||
|
||||
## END CONTRACT TEXT ##
|
||||
|
||||
Finally state "Answer: |YYYY-MM-DD| or |Original Date Format| or |N/A|"
|
||||
"""
|
||||
|
||||
return prompt_template
|
||||
|
||||
AC_DICT = {
|
||||
|
||||
Reference in New Issue
Block a user