gooddata-eval 1.78.1.dev1__py3-none-any.whl → 1.78.1.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gooddata_eval/cli/agentic_runner.py +4 -2
- gooddata_eval/core/agentic/_catalog.py +9 -0
- gooddata_eval/core/agentic/alert_skill.py +230 -81
- gooddata_eval/core/agentic/dashboard_skill.py +80 -1
- gooddata_eval/core/agentic/visualization.py +132 -22
- gooddata_eval/core/chat/sse_client.py +4 -3
- gooddata_eval/core/dataset/from_insights.py +10 -6
- gooddata_eval/core/evaluators/visualization.py +296 -6
- gooddata_eval/core/models.py +20 -4
- gooddata_eval/core/number_format.py +179 -0
- gooddata_eval/core/scoring.py +148 -8
- {gooddata_eval-1.78.1.dev1.dist-info → gooddata_eval-1.78.1.dev3.dist-info}/METADATA +59 -2
- {gooddata_eval-1.78.1.dev1.dist-info → gooddata_eval-1.78.1.dev3.dist-info}/RECORD +16 -15
- {gooddata_eval-1.78.1.dev1.dist-info → gooddata_eval-1.78.1.dev3.dist-info}/WHEEL +0 -0
- {gooddata_eval-1.78.1.dev1.dist-info → gooddata_eval-1.78.1.dev3.dist-info}/entry_points.txt +0 -0
- {gooddata_eval-1.78.1.dev1.dist-info → gooddata_eval-1.78.1.dev3.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -26,7 +26,7 @@ from gooddata_eval.core.agentic.visualization import evaluate_agentic_visualizat
|
|
|
26
26
|
from gooddata_eval.core.agentic.what_if import evaluate_agentic_what_if
|
|
27
27
|
from gooddata_eval.core.config import ReasoningEffort
|
|
28
28
|
from gooddata_eval.core.evaluators._llm_judge import JudgeResponseError
|
|
29
|
-
from gooddata_eval.core.evaluators.visualization import
|
|
29
|
+
from gooddata_eval.core.evaluators.visualization import expectation_options
|
|
30
30
|
from gooddata_eval.core.models import AgenticEvalOutcome, CreatedVisualization, DatasetItem
|
|
31
31
|
from gooddata_eval.core.runner import EvalReport, ItemReport
|
|
32
32
|
from gooddata_eval.core.timing import TraceRecorder
|
|
@@ -119,6 +119,8 @@ def _parse_visualization_expected(expected_output: Any) -> list[CreatedVisualiza
|
|
|
119
119
|
{"visualization": {...}} or {"visualization": [{...}]} <- single/multi candidate
|
|
120
120
|
[{"visualization": {...}}, ...] <- bare list
|
|
121
121
|
"""
|
|
122
|
+
if isinstance(expected_output, dict) and expected_output.get("expects_visualization") is False:
|
|
123
|
+
return []
|
|
122
124
|
if isinstance(expected_output, dict):
|
|
123
125
|
raw_list = expected_output.get("expected_outputs")
|
|
124
126
|
if raw_list is not None:
|
|
@@ -187,7 +189,7 @@ def _dispatch_agentic(
|
|
|
187
189
|
workspace_id=workspace_id,
|
|
188
190
|
question=item.question,
|
|
189
191
|
expected_outputs=_parse_visualization_expected(eo),
|
|
190
|
-
|
|
192
|
+
options=expectation_options(eo),
|
|
191
193
|
k=k,
|
|
192
194
|
gate=gate,
|
|
193
195
|
agent_id=agent_id,
|
|
@@ -67,6 +67,12 @@ class CatalogMetricAlert:
|
|
|
67
67
|
"""Expected group-by attributes; ``None`` means the fixture states no expectation."""
|
|
68
68
|
granularity: AnomalyDetectionGranularity | None = None
|
|
69
69
|
"""Detection interval for an ANOMALY alert (DAY/WEEK/MONTH/...). Not a date filter."""
|
|
70
|
+
comparison: dict[str, str | int | float | None] | None = None
|
|
71
|
+
"""Expected period comparison as ``create_metric_alert`` argument names; ``None`` means unasserted."""
|
|
72
|
+
title: str | None = None
|
|
73
|
+
"""Alert name the user asked for; ``None`` means unasserted."""
|
|
74
|
+
dashboard_id: str | None = None
|
|
75
|
+
"""Dashboard the alert must be bound to; ``None`` means unasserted."""
|
|
70
76
|
|
|
71
77
|
@classmethod
|
|
72
78
|
def from_dict(cls, d: dict) -> CatalogMetricAlert:
|
|
@@ -87,4 +93,7 @@ class CatalogMetricAlert:
|
|
|
87
93
|
filters=d.get("filters"),
|
|
88
94
|
attributes=d.get("attributes"),
|
|
89
95
|
granularity=AnomalyDetectionGranularity.parse(d.get("granularity")),
|
|
96
|
+
comparison=d.get("comparison"),
|
|
97
|
+
title=d.get("title"),
|
|
98
|
+
dashboard_id=d.get("dashboard_id"),
|
|
90
99
|
)
|
|
@@ -58,6 +58,37 @@ _TRIGGER_DISPLAY_TO_API = {"Every time": "ALWAYS", "One time": "ONCE"}
|
|
|
58
58
|
_ALWAYS_TRIGGER_VALUES = {"Every time", "ALWAYS", "not specified"}
|
|
59
59
|
_RELATIVE_OPERATORS = ("INCREASES_BY", "DECREASES_BY", "CHANGES_BY")
|
|
60
60
|
|
|
61
|
+
# Fixture spelling of each period-comparison property -> the create_metric_alert argument.
|
|
62
|
+
_COMPARISON_ARGS = {
|
|
63
|
+
"kind": "comparison_kind",
|
|
64
|
+
"periods_ago": "comparison_periods_ago",
|
|
65
|
+
"date_dataset_id": "comparison_date_dataset_id",
|
|
66
|
+
"date_attribute_id": "comparison_date_attribute_id",
|
|
67
|
+
"arithmetic_operator": "arithmetic_operator",
|
|
68
|
+
}
|
|
69
|
+
# Compared verbatim: object ids are case-sensitive, unlike the enum-valued properties.
|
|
70
|
+
_COMPARISON_ID_ARGS = ("comparison_date_dataset_id", "comparison_date_attribute_id")
|
|
71
|
+
# What create_metric_alert applies when the argument is left out, per its own contract. A
|
|
72
|
+
# metric-to-metric comparison has no periods, so periods_ago defaults only for a period kind.
|
|
73
|
+
_COMPARISON_ARG_DEFAULTS: dict[str, object] = {"comparison_periods_ago": 1, "arithmetic_operator": "DIFFERENCE"}
|
|
74
|
+
_PERIOD_COMPARISON_KINDS = ("PREVIOUS_PERIOD", "SAME_PERIOD_PRIOR_YEAR")
|
|
75
|
+
_NO_COMPARISON_MARKERS = ("none", "no comparison")
|
|
76
|
+
|
|
77
|
+
# AlertEvaluation checks, in report order. Every run is scored on the first group; the second only
|
|
78
|
+
# when the item states the matching expectation.
|
|
79
|
+
_ALERT_CHECKS = (
|
|
80
|
+
"alert_created",
|
|
81
|
+
"operator_correct",
|
|
82
|
+
"threshold_correct",
|
|
83
|
+
"trigger_correct",
|
|
84
|
+
"filters_correct",
|
|
85
|
+
"metric_correct",
|
|
86
|
+
"recipients_correct",
|
|
87
|
+
"attributes_correct",
|
|
88
|
+
"granularity_correct",
|
|
89
|
+
)
|
|
90
|
+
_CONDITIONAL_ALERT_CHECKS = ("comparison_correct", "title_correct", "dashboard_correct")
|
|
91
|
+
|
|
61
92
|
# Expected-recipient spellings that mean the owner of the API token.
|
|
62
93
|
_CURRENT_USER_RECIPIENT = "me"
|
|
63
94
|
_CURRENT_USER_MARKERS = {"me", "myself", "current user", "current_user"}
|
|
@@ -94,6 +125,29 @@ def _parse_recipients(recipients_str: str | None) -> list[str] | None:
|
|
|
94
125
|
return [r.strip() for r in recipients_str.replace(";", ",").split(",") if r.strip()]
|
|
95
126
|
|
|
96
127
|
|
|
128
|
+
def _recipient_list(value: object, *, split_bare: bool) -> list[str]:
|
|
129
|
+
"""A recipient argument as a list, decoded the way gen-ai does before calling the server.
|
|
130
|
+
|
|
131
|
+
The tool schema declares both recipient fields ``anyOf: [array of string, string, null]``,
|
|
132
|
+
and some models send the list JSON-encoded as a string (``'["admin"]'``). Empty or
|
|
133
|
+
``"null"`` means none; any other string that is not a JSON list of strings is a bare
|
|
134
|
+
value -- one user id, or with ``split_bare`` a comma/semicolon-separated email list
|
|
135
|
+
(gen-ai forwards a bare string as one entry; the split is this checker's own leniency).
|
|
136
|
+
A non-string list entry is kept as its ``str()`` so it compares unequal instead of raising.
|
|
137
|
+
"""
|
|
138
|
+
if isinstance(value, list):
|
|
139
|
+
return [str(item) for item in value]
|
|
140
|
+
if not isinstance(value, str) or value.strip() in ("", "null"):
|
|
141
|
+
return []
|
|
142
|
+
try:
|
|
143
|
+
parsed = json.loads(value)
|
|
144
|
+
except ValueError:
|
|
145
|
+
parsed = None
|
|
146
|
+
if isinstance(parsed, list) and all(isinstance(item, str) for item in parsed):
|
|
147
|
+
return parsed
|
|
148
|
+
return (_parse_recipients(value) or []) if split_bare else [value]
|
|
149
|
+
|
|
150
|
+
|
|
97
151
|
def _deep_subset(expected: object, actual: object) -> bool:
|
|
98
152
|
"""Return True if expected is a recursive subset of actual."""
|
|
99
153
|
if isinstance(expected, dict) and isinstance(actual, dict):
|
|
@@ -234,6 +288,66 @@ def _check_granularity(expected: CatalogMetricAlert, actual_args: dict) -> bool:
|
|
|
234
288
|
return str(actual).strip().upper() == expected.granularity.value
|
|
235
289
|
|
|
236
290
|
|
|
291
|
+
def _canonical_comparison_value(arg: str, value: object) -> str | int | float | None:
|
|
292
|
+
"""Fold one comparison value so fixture and tool-argument spellings compare equal."""
|
|
293
|
+
if value is None or str(value).strip() == "":
|
|
294
|
+
return None
|
|
295
|
+
if arg == "comparison_periods_ago":
|
|
296
|
+
return _to_number(value)
|
|
297
|
+
if arg in _COMPARISON_ID_ARGS:
|
|
298
|
+
return str(value).strip()
|
|
299
|
+
return str(value).strip().upper()
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _check_comparison(expected: CatalogMetricAlert, actual_args: dict) -> bool:
|
|
303
|
+
"""Compare only the comparison properties the fixture states.
|
|
304
|
+
|
|
305
|
+
``None`` means unasserted. A stated ``comparison_kind`` of ``None`` asserts the alert has
|
|
306
|
+
no comparison at all. ``comparison_kind`` is read as ``create_metric_alert`` resolves it:
|
|
307
|
+
left out next to a ``compare_metric_id`` it is METRIC. Any other argument the agent left out
|
|
308
|
+
on an alert that does compare counts as the value ``create_metric_alert`` applies for it, so
|
|
309
|
+
omitting ``comparison_periods_ago`` matches 1 on a period comparison; a METRIC comparison has
|
|
310
|
+
no periods, and with no comparison there is nothing to default.
|
|
311
|
+
The comparison period itself (DAY, MONTH, ...) is not checked here: it is the granularity
|
|
312
|
+
of the comparison date filter, which ``filters`` asserts.
|
|
313
|
+
"""
|
|
314
|
+
if expected.comparison is None:
|
|
315
|
+
return True
|
|
316
|
+
kind = actual_args.get("comparison_kind") or ("METRIC" if actual_args.get("compare_metric_id") else None)
|
|
317
|
+
for arg, exp_value in expected.comparison.items():
|
|
318
|
+
act_raw = kind if arg == "comparison_kind" else actual_args.get(arg)
|
|
319
|
+
defaults_apply = arg != "comparison_periods_ago" or str(kind).upper() in _PERIOD_COMPARISON_KINDS
|
|
320
|
+
if act_raw is None and kind is not None and defaults_apply:
|
|
321
|
+
act_raw = _COMPARISON_ARG_DEFAULTS.get(arg)
|
|
322
|
+
# Only the fixture side of an object id is trimmed: a padded id is a different id.
|
|
323
|
+
actual = act_raw if arg in _COMPARISON_ID_ARGS else _canonical_comparison_value(arg, act_raw)
|
|
324
|
+
if actual != exp_value:
|
|
325
|
+
return False
|
|
326
|
+
return True
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def _check_title(expected: CatalogMetricAlert, actual_args: dict) -> bool:
|
|
330
|
+
"""Exact match on the alert name when the fixture states one.
|
|
331
|
+
|
|
332
|
+
Only the fixture side is trimmed: a name saved with padding is not the name the user asked for.
|
|
333
|
+
|
|
334
|
+
An omitted ``title`` fails: ``create_metric_alert`` then saves an auto-generated name, even
|
|
335
|
+
when ``automation_id`` carries a slug of the requested one.
|
|
336
|
+
"""
|
|
337
|
+
if expected.title is None:
|
|
338
|
+
return True
|
|
339
|
+
actual = actual_args.get("title")
|
|
340
|
+
return isinstance(actual, str) and actual == expected.title
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _check_dashboard(expected: CatalogMetricAlert, actual_args: dict) -> bool:
|
|
344
|
+
"""Compare the bound dashboard id when the fixture states one; the actual id verbatim."""
|
|
345
|
+
if expected.dashboard_id is None:
|
|
346
|
+
return True
|
|
347
|
+
actual = actual_args.get("dashboard_id")
|
|
348
|
+
return isinstance(actual, str) and actual == expected.dashboard_id
|
|
349
|
+
|
|
350
|
+
|
|
237
351
|
def _check_metric(expected: CatalogMetricAlert, actual_args: dict) -> bool:
|
|
238
352
|
if not expected.metric_id:
|
|
239
353
|
return True
|
|
@@ -305,35 +419,14 @@ def _check_recipients(
|
|
|
305
419
|
) -> bool:
|
|
306
420
|
if not expected.recipients:
|
|
307
421
|
return True
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
# external_recipients is JSON-encoded (e.g. '["email@example.com"]')
|
|
311
|
-
try:
|
|
312
|
-
parsed = json.loads(act_recip_raw)
|
|
313
|
-
act_recip = parsed if isinstance(parsed, list) else _parse_recipients(act_recip_raw)
|
|
314
|
-
except (json.JSONDecodeError, ValueError):
|
|
315
|
-
act_recip = _parse_recipients(act_recip_raw)
|
|
316
|
-
elif isinstance(act_recip_raw, list):
|
|
317
|
-
act_recip = act_recip_raw
|
|
318
|
-
else:
|
|
319
|
-
act_recip = []
|
|
320
|
-
act_internal_raw = actual_args.get("internal_recipients")
|
|
321
|
-
# internal_recipients is declared `anyOf: [array of string, string, null]` in the
|
|
322
|
-
# create_metric_alert tool schema -- a single id as a bare string is schema-legal,
|
|
323
|
-
# not a malformed call, so it needs the same string/list normalization already
|
|
324
|
-
# applied to recipients/external_recipients above.
|
|
325
|
-
if isinstance(act_internal_raw, str):
|
|
326
|
-
act_internal = [act_internal_raw]
|
|
327
|
-
elif isinstance(act_internal_raw, list):
|
|
328
|
-
act_internal = act_internal_raw
|
|
329
|
-
else:
|
|
330
|
-
act_internal = []
|
|
422
|
+
act_recip = _recipient_list(actual_args.get("recipients", actual_args.get("external_recipients")), split_bare=True)
|
|
423
|
+
act_internal = _recipient_list(actual_args.get("internal_recipients"), split_bare=False)
|
|
331
424
|
wants_current_user, expected_emails = _split_current_user(expected.recipients)
|
|
332
425
|
if wants_current_user:
|
|
333
426
|
if current_user_id is None or current_user_id not in act_internal:
|
|
334
427
|
return False
|
|
335
428
|
other_internal = set(act_internal) - {current_user_id}
|
|
336
|
-
external = set(act_recip
|
|
429
|
+
external = set(act_recip)
|
|
337
430
|
if external - set(expected_emails):
|
|
338
431
|
return False
|
|
339
432
|
# An email not sent externally must arrive as its user's id (workspace-restricted channel).
|
|
@@ -345,7 +438,7 @@ def _check_recipients(
|
|
|
345
438
|
# One lookup per email: a bulk lookup returns only the users that exist, hiding a missing one.
|
|
346
439
|
ids_per_email = [_resolve_internal_recipient_ids(sdk, [email]) for email in unmatched]
|
|
347
440
|
return all(ids_per_email) and other_internal == set().union(*ids_per_email)
|
|
348
|
-
if set(expected_emails) == set(act_recip
|
|
441
|
+
if set(expected_emails) == set(act_recip):
|
|
349
442
|
return True
|
|
350
443
|
if sdk is not None and act_internal:
|
|
351
444
|
internal_recipient_ids = _resolve_internal_recipient_ids(sdk, expected_emails)
|
|
@@ -489,6 +582,15 @@ def generate_simulated_alert_response(
|
|
|
489
582
|
|
|
490
583
|
original_request = f'Your original request to the agent was: "{question}"\n' if question else ""
|
|
491
584
|
|
|
585
|
+
# Only a stated title is enforced: an unstated one is the agent's to choose, and telling the
|
|
586
|
+
# sim-user nothing keeps it from objecting to a generated name.
|
|
587
|
+
title_rule = (
|
|
588
|
+
f'8. The alert must be named exactly "{expected.title}". If a summary or proposal shows a '
|
|
589
|
+
"different name, do NOT confirm: state that exact name and ask the agent to use it.\n"
|
|
590
|
+
if expected.title
|
|
591
|
+
else ""
|
|
592
|
+
)
|
|
593
|
+
|
|
492
594
|
system_prompt = (
|
|
493
595
|
"You are a user requesting creation of an alert for a metric from an AI agent. "
|
|
494
596
|
"Respond naturally but always steer toward the exact values you were given.\n"
|
|
@@ -509,7 +611,10 @@ def generate_simulated_alert_response(
|
|
|
509
611
|
+ recipients_rule
|
|
510
612
|
+ filters_rule
|
|
511
613
|
+ f"6. Proactively state how often you want to be alerted in your first reply: {trigger_request}. "
|
|
512
|
-
" Repeat it if the agent proposes a different cadence.\n"
|
|
614
|
+
" Repeat it if the agent proposes a different cadence.\n"
|
|
615
|
+
+ period_rule
|
|
616
|
+
+ title_rule
|
|
617
|
+
+ "Reply concisely and directly."
|
|
513
618
|
)
|
|
514
619
|
|
|
515
620
|
messages: list = [{"role": "system", "content": system_prompt}]
|
|
@@ -550,22 +655,28 @@ class AlertEvaluation:
|
|
|
550
655
|
recipients_correct: bool
|
|
551
656
|
attributes_correct: bool = True
|
|
552
657
|
granularity_correct: bool = True
|
|
658
|
+
# ``None``: the item states no such expectation, so the check is neither scored nor gated.
|
|
659
|
+
comparison_correct: bool | None = None
|
|
660
|
+
title_correct: bool | None = None
|
|
661
|
+
dashboard_correct: bool | None = None
|
|
662
|
+
|
|
663
|
+
def checks(self) -> dict[str, bool]:
|
|
664
|
+
"""Every check that ran, by name; strict_pass requires all of them.
|
|
665
|
+
|
|
666
|
+
The conditional checks are left out when unasserted, so an item that names no title does
|
|
667
|
+
not report a ``title_correct`` it was never scored on, and a refusal on it is not counted
|
|
668
|
+
as a title failure.
|
|
669
|
+
"""
|
|
670
|
+
ran: dict[str, bool] = {name: getattr(self, name) for name in _ALERT_CHECKS}
|
|
671
|
+
for name in _CONDITIONAL_ALERT_CHECKS:
|
|
672
|
+
value = getattr(self, name)
|
|
673
|
+
if value is not None:
|
|
674
|
+
ran[name] = value
|
|
675
|
+
return ran
|
|
553
676
|
|
|
554
677
|
@property
|
|
555
678
|
def strict_pass(self) -> bool:
|
|
556
|
-
return all(
|
|
557
|
-
[
|
|
558
|
-
self.alert_created,
|
|
559
|
-
self.operator_correct,
|
|
560
|
-
self.threshold_correct,
|
|
561
|
-
self.trigger_correct,
|
|
562
|
-
self.filters_correct,
|
|
563
|
-
self.metric_correct,
|
|
564
|
-
self.recipients_correct,
|
|
565
|
-
self.attributes_correct,
|
|
566
|
-
self.granularity_correct,
|
|
567
|
-
]
|
|
568
|
-
)
|
|
679
|
+
return all(self.checks().values())
|
|
569
680
|
|
|
570
681
|
|
|
571
682
|
@dataclass
|
|
@@ -666,6 +777,68 @@ def _normalize_expected_attributes(expected: dict) -> list | None:
|
|
|
666
777
|
raise ValueError(f"Attributes expectation must be a list or a display string, got {type(attributes).__name__}")
|
|
667
778
|
|
|
668
779
|
|
|
780
|
+
def _normalize_expected_comparison(expected: dict) -> dict[str, str | int | float | None] | None:
|
|
781
|
+
"""
|
|
782
|
+
* ``Comparison`` object -> its stated properties, keyed by tool-argument name
|
|
783
|
+
* "None" / "no comparison" -> ``{"comparison_kind": None}`` (stated: no comparison)
|
|
784
|
+
* absent, empty, or prose -> ``None`` (unstated; comparison not asserted)
|
|
785
|
+
|
|
786
|
+
Each property of the object is asserted only when it carries a value, so an item can pin
|
|
787
|
+
the comparison kind without also pinning the date dataset the agent may pick.
|
|
788
|
+
"""
|
|
789
|
+
comparison = _case_insensitive_get(expected, "comparison")
|
|
790
|
+
if comparison is None:
|
|
791
|
+
return None
|
|
792
|
+
if isinstance(comparison, str):
|
|
793
|
+
return {"comparison_kind": None} if any(kw in comparison.lower() for kw in _NO_COMPARISON_MARKERS) else None
|
|
794
|
+
if not isinstance(comparison, dict):
|
|
795
|
+
raise ValueError(f"Comparison expectation must be an object or a display string, got {comparison!r}")
|
|
796
|
+
stated: dict[str, str | int | float | None] = {}
|
|
797
|
+
for key, value in comparison.items():
|
|
798
|
+
name = str(key).strip().lower()
|
|
799
|
+
arg = _COMPARISON_ARGS.get(name) or (name if name in _COMPARISON_ARGS.values() else None)
|
|
800
|
+
if arg is None:
|
|
801
|
+
# Validated here so a misspelled property fails before the run spends an API call.
|
|
802
|
+
raise ValueError(f"Unrecognised comparison property {key!r}; expected one of {sorted(_COMPARISON_ARGS)}")
|
|
803
|
+
canonical = _canonical_comparison_value(arg, value)
|
|
804
|
+
if canonical is None and arg == "comparison_periods_ago" and str(value or "").strip():
|
|
805
|
+
raise ValueError(f"Comparison periods_ago must be a number, got {value!r}")
|
|
806
|
+
if canonical is not None:
|
|
807
|
+
stated[arg] = canonical
|
|
808
|
+
return stated or None
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
def _normalize_expected_text(expected: dict, *keys: str) -> str | None:
|
|
812
|
+
"""A stated string expectation, or ``None`` when absent or blank (unasserted)."""
|
|
813
|
+
value = _case_insensitive_get(expected, *keys)
|
|
814
|
+
if value is None:
|
|
815
|
+
return None
|
|
816
|
+
if not isinstance(value, str):
|
|
817
|
+
raise ValueError(f"{keys[0]} expectation must be a string, got {value!r}")
|
|
818
|
+
return value.strip() or None
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
def _normalize_expected_dashboard(expected: dict) -> str | None:
|
|
822
|
+
"""
|
|
823
|
+
* ``dashboard_id`` -> that id
|
|
824
|
+
* ``Dashboard`` "Title (id)" -> the id in the trailing parentheses, as ``Metric`` is read
|
|
825
|
+
* absent / empty -> ``None`` (unstated; binding not asserted)
|
|
826
|
+
|
|
827
|
+
A ``Dashboard`` without a trailing ``(id)`` raises: a title alone can never equal the
|
|
828
|
+
``dashboard_id`` the tool receives, so the item would fail on every run.
|
|
829
|
+
"""
|
|
830
|
+
dashboard_id = _normalize_expected_text(expected, "dashboard_id")
|
|
831
|
+
if dashboard_id is not None:
|
|
832
|
+
return dashboard_id
|
|
833
|
+
display = _normalize_expected_text(expected, "dashboard")
|
|
834
|
+
if display is None:
|
|
835
|
+
return None
|
|
836
|
+
parsed = _parse_metric_id(display)
|
|
837
|
+
if parsed is None:
|
|
838
|
+
raise ValueError(f'Dashboard expectation must be "Title (id)", got {display!r}; use dashboard_id for a bare id')
|
|
839
|
+
return parsed
|
|
840
|
+
|
|
841
|
+
|
|
669
842
|
def _normalize_expected_output(expected: dict) -> CatalogMetricAlert:
|
|
670
843
|
"""Parse expected_output dict into CatalogMetricAlert, accepting display-format or internal-format keys."""
|
|
671
844
|
operator = _case_insensitive_get(expected, "operator") or "GREATER_THAN"
|
|
@@ -696,6 +869,9 @@ def _normalize_expected_output(expected: dict) -> CatalogMetricAlert:
|
|
|
696
869
|
granularity = AnomalyDetectionGranularity.parse(
|
|
697
870
|
_case_insensitive_get(expected, "granularity", "detection granularity")
|
|
698
871
|
)
|
|
872
|
+
comparison = _normalize_expected_comparison(expected)
|
|
873
|
+
title = _normalize_expected_text(expected, "title")
|
|
874
|
+
dashboard_id = _normalize_expected_dashboard(expected)
|
|
699
875
|
|
|
700
876
|
return CatalogMetricAlert(
|
|
701
877
|
operator=operator,
|
|
@@ -708,6 +884,9 @@ def _normalize_expected_output(expected: dict) -> CatalogMetricAlert:
|
|
|
708
884
|
filters=filters,
|
|
709
885
|
attributes=attributes,
|
|
710
886
|
granularity=granularity,
|
|
887
|
+
comparison=comparison,
|
|
888
|
+
title=title,
|
|
889
|
+
dashboard_id=dashboard_id,
|
|
711
890
|
)
|
|
712
891
|
|
|
713
892
|
|
|
@@ -893,6 +1072,13 @@ def run_agentic_alert_skill(
|
|
|
893
1072
|
and _check_recipients(expected, actual_args, sdk=sdk, current_user_id=current_user_id),
|
|
894
1073
|
attributes_correct=tool_called and _check_attributes(expected, actual_args),
|
|
895
1074
|
granularity_correct=tool_called and _check_granularity(expected, actual_args),
|
|
1075
|
+
comparison_correct=None
|
|
1076
|
+
if expected.comparison is None
|
|
1077
|
+
else tool_called and _check_comparison(expected, actual_args),
|
|
1078
|
+
title_correct=None if expected.title is None else tool_called and _check_title(expected, actual_args),
|
|
1079
|
+
dashboard_correct=None
|
|
1080
|
+
if expected.dashboard_id is None
|
|
1081
|
+
else tool_called and _check_dashboard(expected, actual_args),
|
|
896
1082
|
)
|
|
897
1083
|
return AlertRunResult(
|
|
898
1084
|
conversation_id=conv_id,
|
|
@@ -934,19 +1120,7 @@ def run_agentic_alert_skill(
|
|
|
934
1120
|
pass_power_k = all(r.eval.strict_pass for r in run_results)
|
|
935
1121
|
best = max(
|
|
936
1122
|
run_results,
|
|
937
|
-
key=lambda r: sum(
|
|
938
|
-
[
|
|
939
|
-
r.eval.alert_created,
|
|
940
|
-
r.eval.operator_correct,
|
|
941
|
-
r.eval.threshold_correct,
|
|
942
|
-
r.eval.trigger_correct,
|
|
943
|
-
r.eval.filters_correct,
|
|
944
|
-
r.eval.metric_correct,
|
|
945
|
-
r.eval.recipients_correct,
|
|
946
|
-
r.eval.attributes_correct,
|
|
947
|
-
r.eval.granularity_correct,
|
|
948
|
-
]
|
|
949
|
-
),
|
|
1123
|
+
key=lambda r: sum(r.eval.checks().values()),
|
|
950
1124
|
)
|
|
951
1125
|
return AgenticAlertSummary(
|
|
952
1126
|
run_results=run_results,
|
|
@@ -966,17 +1140,8 @@ def _run_detail(run: AlertRunResult) -> dict:
|
|
|
966
1140
|
Extracted so a failing run is described by exactly the same keys as the winning run --
|
|
967
1141
|
for this kind that means the full per-field check breakdown and the arguments the run sent.
|
|
968
1142
|
"""
|
|
969
|
-
ev = run.eval
|
|
970
1143
|
return {
|
|
971
|
-
|
|
972
|
-
"operator_correct": ev.operator_correct,
|
|
973
|
-
"threshold_correct": ev.threshold_correct,
|
|
974
|
-
"trigger_correct": ev.trigger_correct,
|
|
975
|
-
"filters_correct": ev.filters_correct,
|
|
976
|
-
"metric_correct": ev.metric_correct,
|
|
977
|
-
"recipients_correct": ev.recipients_correct,
|
|
978
|
-
"attributes_correct": ev.attributes_correct,
|
|
979
|
-
"granularity_correct": ev.granularity_correct,
|
|
1144
|
+
**run.eval.checks(),
|
|
980
1145
|
"actual_alert_arguments": run.actual_alert_arguments,
|
|
981
1146
|
# Why the loop stopped. alert_created=False alone cannot tell a refusal from a run
|
|
982
1147
|
# that hit max_iterations while still on track -- see LoopExit. Per-run rather than
|
|
@@ -1052,18 +1217,7 @@ def evaluate_agentic_alert_skill(
|
|
|
1052
1217
|
|
|
1053
1218
|
for run_idx, run in enumerate(summary.run_results):
|
|
1054
1219
|
pt = ctx.trace(run.conversation_id)
|
|
1055
|
-
|
|
1056
|
-
strict_checks = {
|
|
1057
|
-
"alert_created": ev.alert_created,
|
|
1058
|
-
"operator_correct": ev.operator_correct,
|
|
1059
|
-
"threshold_correct": ev.threshold_correct,
|
|
1060
|
-
"trigger_correct": ev.trigger_correct,
|
|
1061
|
-
"filters_correct": ev.filters_correct,
|
|
1062
|
-
"metric_correct": ev.metric_correct,
|
|
1063
|
-
"recipients_correct": ev.recipients_correct,
|
|
1064
|
-
"attributes_correct": ev.attributes_correct,
|
|
1065
|
-
"granularity_correct": ev.granularity_correct,
|
|
1066
|
-
}
|
|
1220
|
+
strict_checks = run.eval.checks()
|
|
1067
1221
|
with ctx.observe(pt, run_idx, conversation_id=run.conversation_id, output=strict_checks) as tid:
|
|
1068
1222
|
for score_name, value in strict_checks.items():
|
|
1069
1223
|
ctx.score(tid, name=score_name, value=float(value), data_type="BOOLEAN")
|
|
@@ -1112,13 +1266,8 @@ def evaluate_agentic_alert_skill(
|
|
|
1112
1266
|
gate_note = gate_failure_note(gate, runs_passed, runs_effective)
|
|
1113
1267
|
exc = AlertSkillAssertionError(
|
|
1114
1268
|
f"Alert skill assertion failed. {gate_note} strict_pass={ev.strict_pass}. "
|
|
1115
|
-
f"
|
|
1116
|
-
f"
|
|
1117
|
-
f"filters_correct={ev.filters_correct}, metric_correct={ev.metric_correct}, "
|
|
1118
|
-
f"recipients_correct={ev.recipients_correct}, "
|
|
1119
|
-
f"attributes_correct={ev.attributes_correct}, "
|
|
1120
|
-
f"granularity_correct={ev.granularity_correct}. "
|
|
1121
|
-
f"Actual args: {best.actual_alert_arguments}"
|
|
1269
|
+
+ ", ".join(f"{name}={value}" for name, value in ev.checks().items())
|
|
1270
|
+
+ f". Actual args: {best.actual_alert_arguments}"
|
|
1122
1271
|
)
|
|
1123
1272
|
exc.reasoning_steps = best.reasoning_steps
|
|
1124
1273
|
exc.conversation_id = best.conversation_id
|
|
@@ -40,6 +40,7 @@ from gooddata_eval.core.models import (
|
|
|
40
40
|
build_latency_breakdown,
|
|
41
41
|
shift_and_index_events,
|
|
42
42
|
)
|
|
43
|
+
from gooddata_eval.core.scoring import AAC_VISUALIZATION_TYPES, same_viz_type
|
|
43
44
|
from gooddata_eval.core.timing import PhaseTimings, log_timer, sum_timings
|
|
44
45
|
|
|
45
46
|
_DEFAULT_K = 1
|
|
@@ -582,6 +583,64 @@ def _check_date_bindings(widgets: list[dict], new_ids: set[str], expected: list[
|
|
|
582
583
|
return failures
|
|
583
584
|
|
|
584
585
|
|
|
586
|
+
def _has_chart_types(expected_output: dict) -> bool:
|
|
587
|
+
"""Whether any expected chart states the type it must be placed as."""
|
|
588
|
+
return any(isinstance(v, dict) and "chart_type" in v for v in expected_output.get("visualizations") or [])
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def _bodies_by_id(*references: dict) -> dict[str, dict]:
|
|
592
|
+
"""Every chart body the response's references carry, existing and authored, by chart id."""
|
|
593
|
+
bodies: dict[str, dict] = {}
|
|
594
|
+
for refs in references:
|
|
595
|
+
for key in ("visualizations", "new_visualizations"):
|
|
596
|
+
for body in refs.get(key) or []:
|
|
597
|
+
if isinstance(body, dict) and body.get("id"):
|
|
598
|
+
bodies[body["id"]] = body
|
|
599
|
+
return bodies
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
def _check_chart_types(
|
|
603
|
+
widgets: list[dict], new_ids: set[str], expected: list[dict], bodies: dict[str, dict]
|
|
604
|
+
) -> tuple[list[str], list[str]]:
|
|
605
|
+
"""Every widget of a chart that states a ``chart_type`` must show a chart of exactly that type.
|
|
606
|
+
|
|
607
|
+
A widget names only the chart id, so the type is read from the chart body the references
|
|
608
|
+
carry. The title alone cannot catch a chart authored as another type than the one asked
|
|
609
|
+
for, which is the silent swap GDAI-2054 rules out.
|
|
610
|
+
|
|
611
|
+
Returns the failures and the notes. A widget whose chart has no body in the references
|
|
612
|
+
cannot be checked: gen-ai carries a body only when it could resolve one, so a missing
|
|
613
|
+
body is a platform fault, noted as ``_check_references`` notes a missing id, and not
|
|
614
|
+
scored as the agent's.
|
|
615
|
+
"""
|
|
616
|
+
failures: list[str] = []
|
|
617
|
+
notes: list[str] = []
|
|
618
|
+
for exp in expected:
|
|
619
|
+
if not isinstance(exp, dict) or "chart_type" not in exp:
|
|
620
|
+
continue
|
|
621
|
+
wanted = exp["chart_type"]
|
|
622
|
+
label = exp.get("title") if exp.get("id") is None else exp.get("id")
|
|
623
|
+
candidates = _matching_widgets(widgets, new_ids, exp)
|
|
624
|
+
if not candidates:
|
|
625
|
+
failures.append(f"cannot check the type of chart {label!r}: it is not on the dashboard")
|
|
626
|
+
continue
|
|
627
|
+
types: list[str] = []
|
|
628
|
+
for widget in candidates:
|
|
629
|
+
chart_type = (bodies.get(widget.get("visualization")) or {}).get("type")
|
|
630
|
+
if isinstance(chart_type, str):
|
|
631
|
+
types.append(chart_type)
|
|
632
|
+
else:
|
|
633
|
+
notes.append(
|
|
634
|
+
f"cannot check the type of chart {label!r}: the response's references carry no body "
|
|
635
|
+
f"for {widget.get('visualization')!r}"
|
|
636
|
+
)
|
|
637
|
+
# Every placement, as for date bindings: one right placement must not hide a wrong one.
|
|
638
|
+
if not all(same_viz_type(wanted, t) for t in types):
|
|
639
|
+
found = ", ".join(repr(t) for t in types)
|
|
640
|
+
failures.append(f"chart {label!r} is {found}, expected {wanted!r}")
|
|
641
|
+
return failures, notes
|
|
642
|
+
|
|
643
|
+
|
|
585
644
|
def _tabs_of(dashboard: dict) -> list[dict]:
|
|
586
645
|
"""The dashboard's tabs, reading a document with root sections as its single tab."""
|
|
587
646
|
tabs = dashboard.get("tabs")
|
|
@@ -936,6 +995,12 @@ def _validate_layout_expectations(expected_output: dict) -> None:
|
|
|
936
995
|
for chart in expected_output.get("visualizations") or []:
|
|
937
996
|
if isinstance(chart, dict) and "date_dataset" in chart and not _is_dataset_or_null(chart["date_dataset"]):
|
|
938
997
|
raise ValueError(f"date_dataset must name a date dataset or be null, got {chart!r}")
|
|
998
|
+
if (
|
|
999
|
+
isinstance(chart, dict)
|
|
1000
|
+
and "chart_type" in chart
|
|
1001
|
+
and (not isinstance(chart["chart_type"], str) or chart["chart_type"] not in AAC_VISUALIZATION_TYPES)
|
|
1002
|
+
):
|
|
1003
|
+
raise ValueError(f"chart_type must be an AAC visualization type, got {chart!r}")
|
|
939
1004
|
|
|
940
1005
|
if "tabs" in expected_output:
|
|
941
1006
|
tabs = expected_output["tabs"]
|
|
@@ -1037,6 +1102,7 @@ class _Applies:
|
|
|
1037
1102
|
tab_filters: bool = False
|
|
1038
1103
|
date_filters: bool = False
|
|
1039
1104
|
preserved_widgets: bool = False
|
|
1105
|
+
chart_types: bool = False
|
|
1040
1106
|
|
|
1041
1107
|
@classmethod
|
|
1042
1108
|
def of(cls, expected_output: dict) -> _Applies:
|
|
@@ -1049,6 +1115,7 @@ class _Applies:
|
|
|
1049
1115
|
tab_filters="tab_filters" in expected_output,
|
|
1050
1116
|
date_filters="date_filters" in expected_output,
|
|
1051
1117
|
preserved_widgets="preserved_widgets" in expected_output,
|
|
1118
|
+
chart_types=_has_chart_types(expected_output),
|
|
1052
1119
|
)
|
|
1053
1120
|
|
|
1054
1121
|
|
|
@@ -1089,6 +1156,7 @@ class DashboardEvaluation:
|
|
|
1089
1156
|
tab_filters_correct: bool = False
|
|
1090
1157
|
date_filters_correct: bool = False
|
|
1091
1158
|
widgets_preserved: bool = False
|
|
1159
|
+
chart_types_correct: bool = False
|
|
1092
1160
|
failures: list[str] = field(default_factory=list)
|
|
1093
1161
|
notes: list[str] = field(default_factory=list)
|
|
1094
1162
|
|
|
@@ -1129,6 +1197,8 @@ class DashboardEvaluation:
|
|
|
1129
1197
|
checks["dashboard_date_filters_correct"] = self.date_filters_correct
|
|
1130
1198
|
if self.applies.preserved_widgets:
|
|
1131
1199
|
checks["dashboard_widgets_preserved"] = self.widgets_preserved
|
|
1200
|
+
if self.applies.chart_types:
|
|
1201
|
+
checks["dashboard_chart_types_correct"] = self.chart_types_correct
|
|
1132
1202
|
return checks
|
|
1133
1203
|
|
|
1134
1204
|
@property
|
|
@@ -1280,12 +1350,14 @@ def evaluate_dashboard_response(
|
|
|
1280
1350
|
| {v.get("id") for v in patch_references.get("visualizations") or [] if v.get("id")}
|
|
1281
1351
|
| new_ids
|
|
1282
1352
|
)
|
|
1353
|
+
bodies = _bodies_by_id(base_references, patch_references)
|
|
1283
1354
|
else:
|
|
1284
1355
|
if actual_saved_id is not None:
|
|
1285
1356
|
saved_failures.append(f"a new draft must not be saved yet, but it reports id {actual_saved_id!r}")
|
|
1286
1357
|
document = base
|
|
1287
1358
|
new_ids = {v.get("id") for v in base_references.get("new_visualizations") or [] if v.get("id")}
|
|
1288
1359
|
known_ids = {v.get("id") for v in base_references.get("visualizations") or [] if v.get("id")} | new_ids
|
|
1360
|
+
bodies = _bodies_by_id(base_references)
|
|
1289
1361
|
|
|
1290
1362
|
if document is None:
|
|
1291
1363
|
return DashboardEvaluation(
|
|
@@ -1337,6 +1409,11 @@ def evaluate_dashboard_response(
|
|
|
1337
1409
|
preserved_failures = (
|
|
1338
1410
|
_check_preserved_widgets(widgets, expected_output["preserved_widgets"]) if applies.preserved_widgets else []
|
|
1339
1411
|
)
|
|
1412
|
+
chart_type_failures, chart_type_notes = (
|
|
1413
|
+
_check_chart_types(widgets, new_ids, expected_output.get("visualizations") or [], bodies)
|
|
1414
|
+
if applies.chart_types
|
|
1415
|
+
else ([], [])
|
|
1416
|
+
)
|
|
1340
1417
|
|
|
1341
1418
|
return DashboardEvaluation(
|
|
1342
1419
|
drafted=True,
|
|
@@ -1356,6 +1433,7 @@ def evaluate_dashboard_response(
|
|
|
1356
1433
|
tab_filters_correct=not tab_filter_failures,
|
|
1357
1434
|
date_filters_correct=not date_filter_failures,
|
|
1358
1435
|
widgets_preserved=not preserved_failures,
|
|
1436
|
+
chart_types_correct=not chart_type_failures,
|
|
1359
1437
|
failures=[
|
|
1360
1438
|
*chart_failures,
|
|
1361
1439
|
*saved_failures,
|
|
@@ -1366,9 +1444,10 @@ def evaluate_dashboard_response(
|
|
|
1366
1444
|
*tab_filter_failures,
|
|
1367
1445
|
*date_filter_failures,
|
|
1368
1446
|
*preserved_failures,
|
|
1447
|
+
*chart_type_failures,
|
|
1369
1448
|
*new_failures,
|
|
1370
1449
|
],
|
|
1371
|
-
notes=[*title_notes, *reference_notes],
|
|
1450
|
+
notes=[*title_notes, *reference_notes, *chart_type_notes],
|
|
1372
1451
|
)
|
|
1373
1452
|
|
|
1374
1453
|
|