Error types for WPL-AI lexer and parser.
Provides structured errors with line/column information for helpful feedback to LLMs and humans.
Summary
Functions
Create a result tuple from errors.
Extract error summary for quick display (one line per error).
Format an error for display, including source context if available.
Format multiple errors for display.
Format errors for LLM retry - structured feedback that helps the LLM fix issues.
Format WPL validation errors for LLM retry.
Functions
Create a result tuple from errors.
Extract error summary for quick display (one line per error).
Format an error for display, including source context if available.
Format multiple errors for display.
Format errors for LLM retry - structured feedback that helps the LLM fix issues.
This format is optimized for sending back to the LLM to help it self-correct. It includes:
- Clear error descriptions with line numbers
- Specific suggestions for fixes
- The problematic source line
- Context about what was expected
Examples
iex> format_for_llm([error], source)
"""
Your WPL-AI output has errors. Please fix and regenerate:
ERROR 1: [Line 5] Unknown exercise reference 'pushup'
→ Did you mean: push_up
→ Source: pushup 3x10 rpe 7
Remember:
- Exercise names use snake_case: push_up, pull_up, bench_press
- Use exactly 2 spaces for indentation
"""
Format WPL validation errors for LLM retry.
Takes string-based validation errors (from WPL.validate/1) and the original WPL-AI source text, returning structured feedback to help the LLM self-correct.
Includes context-aware reminders based on error keywords.
Examples
iex> format_validation_errors_for_llm(["Goal 1: missing required field 'name'"], source)
"""
Your plan compiled to JSON but failed WPL validation. Fix these issues:
1. Goal 1: missing required field 'name'
Remember:
- Every GOAL must have `name "..."` as a quoted string
...
"""