pocketflow/cookbook/pocketflow-structured-output/README.md

2.2 KiB

Structured Output Demo

A minimal demo application showing how to use PocketFlow to extract structured data from a resume using direct prompting and YAML formatting. Why YAML? Check out the doc.

Features

  • Extracts structured data using prompt engineering
  • Validates output structure before processing

Run It

  1. Install the packages you need with this simple command:

    pip install -r requirements.txt
    
  2. Make sure your OpenAI API key is set:

    export OPENAI_API_KEY="your-api-key-here"
    

    Alternatively, you can edit the utils.py file to include your API key directly.

    Let's do a quick check to make sure your API key is working properly:

    python utils.py
    
  3. Edit data.txt with the resume you want to parse (a sample resume is already included)

  4. Run the application:

    python main.py
    

How It Works

flowchart LR
    parser[ResumeParserNode]

The Resume Parser application uses a single node that:

  1. Takes resume text from the shared state (loaded from data.txt)
  2. Sends the resume to an LLM with a prompt that requests YAML formatted output
  3. Extracts and validates the structured YAML data
  4. Outputs the structured result

Files

Example Output

=== Resume Parser - Structured Output with Indexes & Comments ===


=== STRUCTURED RESUME DATA (Comments & Skill Index List) ===

name: JOHN SMTIH
email: johnsmtih1983@gnail.com
experience:
- {title: SALES MANAGER, company: ABC Corportaion}
- {title: ASST. MANAGER, company: XYZ Industries}
- {title: CUSTOMER SERVICE REPRESENTATIVE, company: Fast Solutions Inc}
skill_indexes: [0, 1, 2, 3, 4]


============================================================

✅ Extracted resume information.

--- Found Target Skills (from Indexes) ---
- Team leadership & management (Index: 0)
- CRM software (Index: 1)
- Project management (Index: 2)
- Public speaking (Index: 3)
- Microsoft Office (Index: 4)
----------------------------------------