AI Workflow: Optimizing Resume Parsing with LLM Agents

AlexSurfer Intermediate 1h ago Updated Jul 25, 2026 126 views 7 likes 2 min read

Most resume-parsing scripts fail because they rely on rigid Regex patterns that break the moment a candidate uses a two-column layout or a non-standard header. I've been trying to build an automated screening agent to categorize incoming CVs for a project, but I hit a wall where the LLM was hallucinating experience years because it couldn't distinguish between "Project Duration" and "Total Work Experience."

The core issue was the prompt engineering—I was asking the model to "extract years of experience," which led it to sum up every date it saw on the page.

The Debugging Process

I started by dumping the raw text output of my PDF parser (using PyMuPDF) into a log file. I noticed that the text extraction was interleaving columns, meaning a date from the right column was appearing in the middle of a sentence from the left column.

The Error Pattern:
Input: 2021-2023 Senior Dev Company A Jan 2018-2020 Junior Dev Company B
LLM Output: Total Experience: 5 years (Incorrectly summing disparate roles instead of calculating the timeline).

To fix this, I shifted from a simple extraction prompt to a structured AI workflow that forces the model to first map the timeline chronologically before calculating the total.

The Fix: Implementation Logic

I implemented a two-step chain. First, the agent must output a JSON array of every single date range found, paired with the job title. Second, a Python function calculates the delta between the earliest and latest dates, ignoring overlaps.

Here is the specific system prompt and the validation logic I used to stop the hallucinations:

{
  "system_prompt": "You are a precise data extractor. Extract all employment history into a JSON list. Each object must contain 'start_date', 'end_date', and 'role'. If a date is listed as 'Present', use the current date 2024-05-20. Do not summarize or calculate totals; only extract raw dates.",
  "extraction_schema": [
    {
      "role": "string",
      "start_date": "YYYY-MM-DD",
      "end_date": "YYYY-MM-DD"
    }
  ]
}

Then, I used this Python snippet to handle the actual calculation, which is far more reliable than letting the LLM do math:

from datetime import datetime

def calculate_total_experience(experience_list):
    if not experience_list:
        return 0
    
    # Sort by start date to handle overlaps
    sorted_exp = sorted(experience_list, key=lambda x: x['start_date'])
    
    total_days = 0
    last_end_date = datetime.strptime(sorted_exp[0]['start_date'], '%Y-%m-%d')
    
    for exp in sorted_exp:
        start = datetime.strptime(exp['start_date'], '%Y-%m-%d')
        end = datetime.strptime(exp['end_date'], '%Y-%m-%d')
        
        if start > last_end_date:
            last_end_date = start
            
        if end > last_end_date:
            total_days += (end - last_end_date).days
            last_end_date = end
            
    return total_days / 365.25

Final Results

By moving the "math" out of the prompt and into a post-processing script, the accuracy of the experience extraction jumped from roughly 65% to 94% across a test set of 100 diverse resume formats.

For anyone building a similar LLM agent for HR tech, the lesson is clear: use the LLM for unstructured-to-structured transformation, but never trust it with date arithmetic or summation. For more refined prompt structures, you can check out the resources at promptcube3.com.

Help Needed

All Replies (2)

C
ChrisPunk Novice 9h ago
How are you handling the token limit for longer CVs? Curious if you're chunking the text or using a larger context window.
0 Reply
C
CameronCat Intermediate 9h ago
Are you cleaning the PDFs first? I found that some tools scramble the text order on multi-column layouts before the LLM even sees it.
0 Reply

Write a Reply

Markdown supported