|
| 1 | +# Line-by-Line Evaluation Sample |
| 2 | + |
| 3 | +This sample demonstrates the line-by-line evaluation feature for output evaluators. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Line-by-line evaluation allows evaluators to: |
| 8 | +- Split multi-line outputs by a configurable delimiter (e.g., `\n`) |
| 9 | +- Evaluate each line independently |
| 10 | +- Provide partial credit based on the percentage of correct lines |
| 11 | +- Return detailed per-line feedback |
| 12 | + |
| 13 | +## Features Demonstrated |
| 14 | + |
| 15 | +- **Partial Credit Scoring**: Get 0.67 for 2/3 correct lines instead of 0.0 |
| 16 | +- **Per-Line Feedback**: See exactly which lines passed or failed |
| 17 | +- **Configurable Delimiter**: Use `\n`, `|`, or any custom delimiter |
| 18 | +- **Comparison**: Side-by-side comparison with regular evaluation |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +This sample uses the UiPath package from TestPyPI: |
| 23 | + |
| 24 | +```bash |
| 25 | +# Install dependencies |
| 26 | +uv sync |
| 27 | + |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +### Run the agent |
| 33 | + |
| 34 | +```bash |
| 35 | +uv run uipath run main '{"items": ["apple", "banana", "cherry"]}' |
| 36 | +``` |
| 37 | + |
| 38 | +### Run evaluations |
| 39 | + |
| 40 | +```bash |
| 41 | +uv run uipath eval main evaluations/eval-sets/default.json --workers 1 |
| 42 | +``` |
| 43 | + |
| 44 | +## Evaluation Results |
| 45 | + |
| 46 | +The sample includes three test cases with five evaluators: |
| 47 | + |
| 48 | +### ExactMatch Evaluators |
| 49 | +- **LineByLineExactMatch** - New evaluator with line-by-line support |
| 50 | +- **RegularExactMatch** - New evaluator without line-by-line (for comparison) |
| 51 | +- **LegacyLineByLineExactMatch** - Legacy evaluator with line-by-line support |
| 52 | + |
| 53 | +### Contains Evaluators |
| 54 | +- **LineByLineContains** - New evaluator with line-by-line support (checks if each line contains the search text) |
| 55 | +- **RegularContains** - New evaluator without line-by-line (checks if the entire output contains the search text) |
| 56 | + |
| 57 | +Test cases: |
| 58 | +1. **All lines match exactly** - All evaluators score 1.0 |
| 59 | +2. **One line doesn't match** - Line-by-line ExactMatch: 0.67, Regular ExactMatch: 0.0 (shows partial credit!) |
| 60 | +3. **Single item** - All evaluators score 1.0 |
| 61 | + |
| 62 | +Expected output (showing ExactMatch evaluators): |
| 63 | +``` |
| 64 | +┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 65 | +┃ Evaluation ┃ LineByLineExactMatch ┃ RegularExactMatch ┃ LegacyLineByLineExactMatch ┃ |
| 66 | +┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ |
| 67 | +│ Test all lines match │ 1.0 │ 1.0 │ 1.0 │ |
| 68 | +│ Test when one line doesn't │ 0.7 │ 0.0 │ 0.7 │ ← Key difference! |
| 69 | +│ Test with single item │ 1.0 │ 1.0 │ 1.0 │ |
| 70 | +├───────────────────────────────┼────────────────────────┼─────────────────────┼───────────────────────────────┤ |
| 71 | +│ Average │ 0.9 │ 0.7 │ 0.9 │ |
| 72 | +└───────────────────────────────┴────────────────────────┴─────────────────────┴───────────────────────────────┘ |
| 73 | +``` |
| 74 | + |
| 75 | +Contains evaluators will all score 1.0 since all test outputs contain "Item:". |
| 76 | + |
| 77 | +## Configuration |
| 78 | + |
| 79 | +### Evaluator Configuration |
| 80 | + |
| 81 | +#### New Evaluators (Version-based) |
| 82 | + |
| 83 | +The line-by-line evaluator is configured in `evaluations/evaluators/line-by-line-exact-match.json`: |
| 84 | + |
| 85 | +```json |
| 86 | +{ |
| 87 | + "version": "1.0", |
| 88 | + "evaluatorTypeId": "uipath-exact-match", |
| 89 | + "evaluatorConfig": { |
| 90 | + "name": "LineByLineExactMatch", |
| 91 | + "targetOutputKey": "result", |
| 92 | + "lineByLineEvaluator": true, |
| 93 | + "lineDelimiter": "\n" |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +#### Legacy Evaluators (Category/Type-based) |
| 99 | + |
| 100 | +Legacy evaluators also support line-by-line evaluation in `evaluations/evaluators/legacy-line-by-line-exact-match.json`: |
| 101 | + |
| 102 | +```json |
| 103 | +{ |
| 104 | + "category": "Deterministic", |
| 105 | + "type": "Equals", |
| 106 | + "name": "LegacyLineByLineExactMatch", |
| 107 | + "targetOutputKey": "result", |
| 108 | + "lineByLineEvaluation": true, |
| 109 | + "lineDelimiter": "\n" |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +#### Contains Evaluators |
| 114 | + |
| 115 | +The Contains evaluator checks if the output contains a specific search text. In line-by-line mode, it checks each line independently: |
| 116 | + |
| 117 | +**Line-by-line Contains** (`evaluations/evaluators/line-by-line-contains.json`): |
| 118 | +```json |
| 119 | +{ |
| 120 | + "version": "1.0", |
| 121 | + "evaluatorTypeId": "uipath-contains", |
| 122 | + "evaluatorConfig": { |
| 123 | + "name": "LineByLineContains", |
| 124 | + "target_output_key": "result", |
| 125 | + "line_by_line_evaluator": true, |
| 126 | + "line_delimiter": "\n", |
| 127 | + "case_sensitive": false, |
| 128 | + "negated": false |
| 129 | + } |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +**Regular Contains** (`evaluations/evaluators/regular-contains.json`): |
| 134 | +```json |
| 135 | +{ |
| 136 | + "version": "1.0", |
| 137 | + "evaluatorTypeId": "uipath-contains", |
| 138 | + "evaluatorConfig": { |
| 139 | + "name": "RegularContains", |
| 140 | + "target_output_key": "result", |
| 141 | + "line_by_line_evaluator": false, |
| 142 | + "case_sensitive": false, |
| 143 | + "negated": false |
| 144 | + } |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +In evaluation criteria, specify the search text: |
| 149 | +```json |
| 150 | +{ |
| 151 | + "LineByLineContains": { |
| 152 | + "searchText": "Item:" |
| 153 | + } |
| 154 | +} |
| 155 | +``` |
| 156 | + |
| 157 | +**Behavior difference**: |
| 158 | +- **Line-by-line**: Checks if each line contains "Item:", gives partial credit (e.g., 2/3 if one line is missing it) |
| 159 | +- **Regular**: Checks if the entire output contains "Item:" at least once, returns 1.0 or 0.0 |
| 160 | + |
| 161 | +Key options for all evaluator types: |
| 162 | +- `lineByLineEvaluator`/`lineByLineEvaluation`: Enable line-by-line evaluation (default: `false`) |
| 163 | +- `lineDelimiter`: Delimiter to split lines (default: `"\n"`) |
| 164 | +- `case_sensitive`: Case-sensitive comparison (default: `false` for Contains, `true` for ExactMatch) |
| 165 | +- `negated`: Invert the result (default: `false`, only for Contains) |
| 166 | + |
| 167 | +### Custom Delimiters |
| 168 | + |
| 169 | +You can use any delimiter: |
| 170 | + |
| 171 | +```json |
| 172 | +{ |
| 173 | + "evaluatorConfig": { |
| 174 | + "lineByLineEvaluator": true, |
| 175 | + "lineDelimiter": "|" // Pipe-separated values |
| 176 | + } |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +## File Structure |
| 181 | + |
| 182 | +``` |
| 183 | +line_by_line_test/ |
| 184 | +├── main.py # Simple agent that outputs one item per line |
| 185 | +├── uipath.json # Agent configuration |
| 186 | +├── pyproject.toml # Dependencies (uses TestPyPI) |
| 187 | +└── evaluations/ |
| 188 | + ├── evaluators/ |
| 189 | + │ ├── line-by-line-exact-match.json # New line-by-line ExactMatch evaluator |
| 190 | + │ ├── regular-exact-match.json # New regular ExactMatch evaluator |
| 191 | + │ ├── legacy-line-by-line-exact-match.json # Legacy line-by-line ExactMatch evaluator |
| 192 | + │ ├── line-by-line-contains.json # New line-by-line Contains evaluator |
| 193 | + │ └── regular-contains.json # New regular Contains evaluator |
| 194 | + └── eval-sets/ |
| 195 | + └── default.json # Test cases with all 5 evaluators |
| 196 | +``` |
| 197 | + |
| 198 | +## Learn More |
| 199 | + |
| 200 | +- [UiPath Python SDK Documentation](https://docs.uipath.com/) |
| 201 | +- [Evaluation Framework Guide](../../src/uipath/_resources/eval.md) |
0 commit comments