Enhancing AI-Driven CV Generation with Structured Context and User Control

Crafting a compelling CV often requires tailoring it precisely to a job description. In the landing project, our goal is to automate this process, allowing users to generate customized CVs with ease. Initially, our AI could extract information, but we discovered that without robust data structures and explicit user control, the generated CVs sometimes missed crucial nuances.

The Challenge of Unstructured Data

Job descriptions, while informative, are often free-form text. Extracting key attributes like work modality (remote, hybrid, on-site), contract type (full-time, part-time), and seniority level (junior, senior) accurately and consistently can be tricky. The AI might infer these values, but misinterpretations can lead to a less-than-perfect CV. Our initial approach lacked a clear, structured way to hold this extracted context, making it hard to validate, normalize, and most importantly, for users to refine.

Furthermore, a critical bug in the CvController meant that even when the context was extracted, it wasn't being passed correctly for CV generation, hindering the entire process.

Architecting for Precision: DTOs, Enums, and Overrides

To address these challenges, we implemented several key improvements, focusing on data structure, type safety, and user empowerment:

1. The CvGenerationContext DTO

We introduced a CvGenerationContext Data Transfer Object (DTO). This object now serves as a single, immutable container for all the job context data extracted by the AI. Instead of passing individual parameters, the DTO encapsulates related data, making the code cleaner, more readable, and less prone to errors.

final class CvGenerationContext
{
    public function __construct(
        public readonly string $jobTitle,
        public readonly WorkModality $workModality,
        public readonly ContractType $contractType,
        public readonly SeniorityLevel $seniorityLevel,
        // ... other context fields
    ) {}
}

2. Type-Safe Enums for Key Attributes

For WorkModality, ContractType, and SeniorityLevel, we migrated from simple strings to PHP Enums. This provides several benefits:

  • Type Safety: Guarantees that these fields will always hold one of the predefined valid values.
  • Readability: Code using enums is more self-documenting.
  • Maintainability: Easier to add or modify options in the future.
enum WorkModality: string
{
    case Remote = 'remote';
    case Hybrid = 'hybrid';
    case OnSite = 'on-site';
}

enum ContractType: string
{
    case FullTime = 'full-time';
    case PartTime = 'part-time';
    case Contract = 'contract';
}

enum SeniorityLevel: string
{
    case Junior = 'junior';
    case Middle = 'middle';
    case Senior = 'senior';
    case Lead = 'lead';
}

3. Intelligent Context Extraction and Normalization

A dedicated extractJobContext() method now handles parsing the raw job description. It uses sophisticated logic to identify keywords, map them to our new Enum values, and normalize the data (e.g., lowercasing all prompt values for consistent matching). This ensures that even varied phrasing in job descriptions can be correctly interpreted.

4. User Overrides for Enhanced Control

The most crucial improvement for user experience is the ability to override AI-detected values. After the AI processes a job description, the inferred Work Modality, Contract Type, and Seniority Level are displayed in the form. Users can review these and, if necessary, adjust them manually. This blends the efficiency of AI with the indispensable precision of human insight, ensuring the CV perfectly matches their expectations.

5. Fixing the CvController

The CvController was refactored to correctly utilize the CvGenerationContext DTO. It now calls extractJobContext() to gather data from the job description and construct the DTO before invoking the CV generation logic. This resolved the critical bug and streamlined the entire process.

The Outcome

By introducing structured DTOs, type-safe Enums, intelligent extraction, and user override capabilities, we've significantly enhanced the accuracy and flexibility of our AI-driven CV generation. The system is more robust, maintainable, and ultimately provides a better experience for users, allowing them to produce highly targeted CVs with confidence.

Actionable Takeaway

When building AI-powered features, especially those involving text extraction, prioritize defining clear, type-safe data structures like DTOs and Enums. Always provide users with an opportunity to review and override AI inferences, as this hybrid approach combines the speed of automation with the accuracy of human expertise, leading to more reliable and trustworthy outcomes.

Enhancing AI-Driven CV Generation with Structured Context and User Control
GERARDO RUIZ

GERARDO RUIZ

Author

Share: