Storage
DynamoDB for experiment rows, S3 for full result JSON. Schema, experiment resolution, and configuration: Persistence and Configuration.
uaef.storage.dynamodb_s3
DynamoDB + S3 storage layer for UAEF experiments and evaluation results.
DynamoDB: One row per experiment with average scores and metadata. S3: Full evaluation results as JSON per experiment.
DynamoS3Storage
Storage layer using DynamoDB for experiment metadata and S3 for full results.
DynamoDB schema (one row per experiment): - experiment_id (PK): str - experiment_name: str - experiment_objective: str | None - created_at: str (ISO 8601) - updated_at: str (ISO 8601) - evaluation_count: int - average_scores: dict (metric_name -> average score) - overall_average_score: Decimal - result_path: str (s3://bucket/prefix/experiment_id.json) - metadata: dict
S3 object (one JSON file per experiment): { "experiment_id": "...", "experiment_name": "...", "evaluations": [ ... full EvaluationResult dicts ... ] }
Source code in uaef/storage/dynamodb_s3.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
account_id
cached
property
Caller's AWS account, resolved on first S3 use (STS GetCallerIdentity).
Every S3 call passes it as ExpectedBucketOwner so results are never read from or written to a same-named bucket in someone else's account.
bucket
cached
property
Results bucket: the configured name, else uaef-results-
Bucket names are global, so a fixed default could resolve to a bucket owned by another account.
create_bucket_if_not_exists()
Create the S3 bucket if it does not already exist.
Source code in uaef/storage/dynamodb_s3.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
create_table_if_not_exists()
Create the DynamoDB table if it does not already exist.
Source code in uaef/storage/dynamodb_s3.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
delete_experiment(experiment_id)
Delete an experiment from DynamoDB and S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Experiment ID to delete. |
required |
Source code in uaef/storage/dynamodb_s3.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
get_experiment(experiment_id)
Get experiment metadata from DynamoDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Experiment ID. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
DynamoDB item dict or None if not found. |
Source code in uaef/storage/dynamodb_s3.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
get_experiment_by_name(name)
Find an experiment by name via DynamoDB scan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Experiment name to search for. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
DynamoDB item dict or None if not found. |
Source code in uaef/storage/dynamodb_s3.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
get_full_results(experiment_id)
Get the full evaluation results from S3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Experiment ID. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Full results dict including all evaluations. |
Source code in uaef/storage/dynamodb_s3.py
369 370 371 372 373 374 375 376 377 378 379 380 | |
list_experiments(created_by=None)
List experiments from DynamoDB.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
created_by
|
Optional[str]
|
Security review H-02: when provided, scopes the
listing to experiments owned by this identity (e.g. a
Cognito |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of experiment item dicts. |
Source code in uaef/storage/dynamodb_s3.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
save_experiment(experiment_id, experiment_name, evaluation_results, experiment_objective=None, metadata=None, created_by=None)
Save or update an experiment with its evaluation results.
Computes average scores from all evaluation results, writes the full results to S3, and upserts the DynamoDB row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Unique experiment identifier. |
required |
experiment_name
|
str
|
Human-readable name. |
required |
evaluation_results
|
List[Dict[str, Any]]
|
List of EvaluationResult dicts (serialized). |
required |
experiment_objective
|
Optional[str]
|
Optional description/objective. |
None
|
metadata
|
Optional[Dict[str, Any]]
|
Optional extra metadata. |
None
|
created_by
|
Optional[str]
|
Security review H-02: the identity (e.g. Cognito
|
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
The DynamoDB item dict that was written. |
Source code in uaef/storage/dynamodb_s3.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
get_storage(config=None)
Get or create the global DynamoS3Storage instance.
Source code in uaef/storage/dynamodb_s3.py
455 456 457 458 459 460 | |
reset_storage()
Reset the global storage instance.
Source code in uaef/storage/dynamodb_s3.py
463 464 465 466 | |
uaef.data.ground_truth
Ground truth parsing and validation utilities.
Shared logic for loading, parsing, and validating ground truth datasets from various formats (CSV, Excel, JSON). Used by the demo backend, notebooks, and any future CLI or API endpoints.
ValidationResult
Bases: BaseModel
Result of ground truth validation.
Source code in uaef/data/ground_truth.py
39 40 41 42 43 44 45 46 47 48 49 50 | |
build_ground_truth(row, events=None)
Build a (query, GroundTruth) pair from a single ground truth row.
If the row has a context column, that value is used. Otherwise, if stream events are provided, tool result contents are extracted as context documents across supported agent frameworks (LangGraph, Strands, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
Dict[str, Any]
|
Dictionary representing a single ground truth row. |
required |
events
|
Optional[List[Dict[str, Any]]]
|
Optional list of agent stream events (for ToolMessage fallback). |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[str, GroundTruth]
|
Tuple of (query, GroundTruth). |
Source code in uaef/data/ground_truth.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
build_multi_turn_ground_truth(turns, events=None)
Build a GroundTruth from multiple conversation turns.
Aggregates expected tool calls across all turns. The top-level
expected_output is the combined per-turn expected answers (with
turn labels), used by full-trace metrics like
ConversationCompletenessMetric. Per-turn expected outputs are also
stored in expected_arguments["per_turn_expected"] as a list so
that per-turn evaluation can create isolated ground truths per turn.
Context is sourced from the context column of any turn that has it; falls back to tool result contents from the provided events across supported agent frameworks (LangGraph, Strands, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
turns
|
List[Dict[str, Any]]
|
List of row dicts, one per conversation turn. |
required |
events
|
Optional[List[Dict[str, Any]]]
|
Optional list of agent stream events (for ToolMessage fallback). |
None
|
Returns:
| Type | Description |
|---|---|
GroundTruth
|
Aggregated GroundTruth for the multi-turn session. |
Source code in uaef/data/ground_truth.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
extract_context_from_trace(trace)
Extract context documents from a canonical trace's tool output.
Framework-agnostic counterpart to :func:_extract_tool_message_context,
which needs raw provider events and so needs a per-framework extractor.
Working from the canonical trace instead means one implementation serves
every adapter, and callers that already hold a trace (the service worker,
for instance) don't have to keep the raw payload around to get context.
Two sources, in order:
ToolCall.resulton the trace's tool calls — the intended home for tool output.Messageentries with roletool— used by adapters that record tool output as conversation turns rather than on the call.
MultiAgentTrace is walked per sub-agent, because a supervisor's own
trace usually holds no tool calls: the work happens in the sub-agents.
Returns an empty list when the trace carries no tool output. That is a real outcome, not a failure: some adapters record tool calls without their results, in which case there is nothing to ground a hallucination check on and the metric should report itself unavailable rather than invent context.
Source code in uaef/data/ground_truth.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
load_ground_truth_file(path=None, content=None, filename=None)
Load ground truth data from a file path or raw bytes.
Supports CSV and Excel (.xlsx, .xls) formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Optional[str]
|
File path to load from. Mutually exclusive with content. |
None
|
content
|
Optional[bytes]
|
Raw file bytes. Requires filename for format detection. |
None
|
filename
|
Optional[str]
|
Original filename (used for format detection with content). |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with ground truth data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither path nor content is provided, or format is unsupported. |
Source code in uaef/data/ground_truth.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
parse_ground_truth_dataframe(df)
Parse an entire DataFrame into (query, GroundTruth) pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame with ground truth data. |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple[str, GroundTruth]]
|
List of (query_string, GroundTruth) tuples. |
Source code in uaef/data/ground_truth.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |
parse_ground_truth_row(row, query_only=False)
Extract query, expected answer, context, and expected tool calls from a ground truth row.
Handles case-insensitive column names and multiple naming conventions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
Dict[str, Any]
|
Dictionary representing a single ground truth row. |
required |
query_only
|
bool
|
If True, only extracts and returns the query string. Useful when you need the query before running the agent and will build the GroundTruth separately. |
False
|
Returns:
| Type | Description |
|---|---|
Union[str, Tuple[str, str, str, List[ToolCall]]]
|
When query_only is False: Tuple of (query, expected_answer, context, expected_tool_calls). |
Union[str, Tuple[str, str, str, List[ToolCall]]]
|
When query_only is True: query string only. |
Source code in uaef/data/ground_truth.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
validate_ground_truth(df, filename='', preview_rows=5)
Validate a ground truth DataFrame and return structured results.
Checks for required columns, detects naming conventions, and produces a preview of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to validate. |
required |
filename
|
str
|
Original filename for reporting. |
''
|
preview_rows
|
int
|
Number of rows to include in the preview. |
5
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult with validation status, column mapping, warnings, and preview. |
Source code in uaef/data/ground_truth.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
uaef.utils.serialization
Shared serialization for EvaluationResult objects.
This is the single source of truth for converting EvaluationResult objects to/from JSON-compatible dicts. Used by both: - Local file persistence (save_metric_results / load_metric_results) - S3 persistence (DynamoS3Storage.save_experiment)
deserialize_results(data)
Deserialize a list of dicts back into EvaluationResult objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
List[Dict[str, Any]]
|
List of dicts (as produced by serialize_results) |
required |
Returns:
| Type | Description |
|---|---|
List[EvaluationResult]
|
List of EvaluationResult objects |
Source code in uaef/utils/serialization.py
34 35 36 37 38 39 40 41 42 43 44 | |
serialize_results(results)
Serialize a list of EvaluationResult objects to JSON-compatible dicts.
This is the canonical serialization used everywhere results are persisted (local JSON files, S3 storage, API responses).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
List[EvaluationResult]
|
List of EvaluationResult objects |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of JSON-serializable dicts |
Source code in uaef/utils/serialization.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
uaef.utils.save_metrics
Utility for saving and loading evaluation metric results.
Uses the same serialization format as the S3 persistence layer (EvaluationResult.model_dump(mode="json")), ensuring that results saved locally can be loaded identically to those retrieved from S3.
The JSON format is
{ "experiment_name": "...", "evaluations": [ {evaluation_result_dict}, ... ] }
This matches the structure written by DynamoS3Storage._write_s3_results().
load_metric_results(path)
Load EvaluationResult objects from a saved JSON file.
Handles both formats: - Local format: {"evaluations": [...], ...} (same as S3) - Legacy format: [...] (flat list of evaluation dicts)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the JSON file produced by save_metric_results() or downloaded from S3 via get_full_results() |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of EvaluationResult objects |
Examples:
>>> from uaef.utils import load_metric_results
>>> results = load_metric_results("output/evaluation-results/my_run.json")
Source code in uaef/utils/save_metrics.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
save_metric_results(results, test_cases=None, *, prefix='batch_results', output_dir=None, query_key='query', expected_key='expected_output', experiment_name=None)
Save evaluation metric results to timestamped JSON and CSV files.
The JSON uses the same format as DynamoS3Storage (with an "evaluations" wrapper), ensuring local saves and S3 downloads are interchangeable. The CSV is a flat, human-readable companion artifact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
List of EvaluationResult objects from evaluate() or batch_evaluate() |
required | |
test_cases
|
Optional[List[Dict]]
|
Optional list of test case dicts for the CSV (not required for JSON) |
None
|
prefix
|
str
|
Filename prefix (default: "batch_results") |
'batch_results'
|
output_dir
|
Optional[str]
|
Output directory (default: BATCH_EVAL_OUTPUT_DIR) |
None
|
query_key
|
str
|
Key in test_cases for the query text (CSV only) |
'query'
|
expected_key
|
str
|
Key in test_cases for the expected output text (CSV only) |
'expected_output'
|
experiment_name
|
Optional[str]
|
Optional name stored in the JSON metadata |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the saved JSON file (use this path with load_metric_results) |
Examples:
>>> from uaef.utils import save_metric_results
>>> filepath = save_metric_results(results, test_cases, prefix="strands_weather")
>>> # Or without test_cases (JSON-only, no CSV):
>>> filepath = save_metric_results(results, prefix="my_run")
Source code in uaef/utils/save_metrics.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |