Skip to content
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved

- `validate` Tier 1 output: when only the `--llm` / `--llm-verify` stage
can't run, `what to fix` gives the exact `export` lines for the missing
provider or key instead of a scanner install or `--skip security`, and the
scanners row keeps the scanner version (`SkillSpector 2.12.0, LLM didn't
run`). A missing SkillSpector or a rejected baseline under `--llm` still
gets the scanner fix, and a `SKILLSPECTOR_PROVIDER` adapter set directly
gets advice for its own key instead of the public provider's. The summary
row now also gives the sub-check count (`9/10 checks passed (22
sub-checks)`). It counts validators, as the `Tier 1: 9 of 10 checks passed`
verdict line under it does, so the two agree, including with `--skip` and
`--fail-fast`.

- Configure CLI stdout to replace characters that its encoding cannot
represent, so reports and root help complete on legacy Windows code pages.
JSON dataset previews and validation output preserve Unicode values, using
Expand Down
112 changes: 101 additions & 11 deletions src/skillevaluator/reporting/console_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import threading
import time
import unicodedata
from collections import Counter
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, TextIO
Expand All @@ -51,6 +52,7 @@
source_validation_errors,
source_validation_preview,
)
from skillevaluator.reporting.presentation import result_execution_status
from skillevaluator.reporting.terminal_styles import (
AMBER,
BRIGHT,
Expand Down Expand Up @@ -909,7 +911,8 @@ def _scanners_row(results: list[ValidationResult]) -> list[TierRow]:
states[scanner] = (version, MUTED)
for scan in r.incomplete_scans:
if (scanner := scan.removesuffix("-llm")) in _SCANNER_NAMES:
states[scanner] = ("didn't run", f"bold {RED}")
version = r.scanners.get(scanner) if scan != scanner else None
states[scanner] = (f"{version}, LLM didn't run" if version else "didn't run", f"bold {RED}")
segments: list[tuple[str, str]] = []
for scanner in [name for name in _SCANNER_NAMES if name in states]:
state, style = states[scanner]
Expand Down Expand Up @@ -1143,7 +1146,6 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None =
results = [r for r in results if not _is_not_applicable(r)]

user_skipped = [r for r in results if _is_user_skipped(r)]
total = len(results) - len(user_skipped)
failed = [r for r in results if not r.passed and not _is_skipped(r)]
incomplete = [r for r in failed if r.is_incomplete]
broken = [r for r in failed if not r.is_incomplete]
Expand All @@ -1160,13 +1162,22 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None =
if lineup:
rows.append(final_check_ticker_row(lineup, results))
rows += scanners
checks_segments: list[tuple[str, str]] = [(f"{total - len(failed)}/{total} passed", TEXT)]
if broken:
checks_segments += [(" · ", FAINT), (f"{len(broken)} failed", f"bold {RED}")]
if incomplete:
checks_segments += [(" · ", FAINT), (f"{len(incomplete)} didn't run", f"bold {RED}")]
if user_skipped:
checks_segments += [(" · ", FAINT), (f"{len(user_skipped)} skipped", MUTED)]

# Count validators with the verdict line's own classification (TierPresentation), so the two agree.
outcome = {id(r): result_execution_status(r) for r in results}
count = Counter(outcome.values())
executed = count["pass"] + count["fail"] + count["incomplete"]
checks_segments: list[tuple[str, str]] = [(f"{count['pass']}/{executed} checks passed", TEXT)]
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
if sub_checks := sum(
r.summary.checks_performed for r in results if outcome[id(r)] in {"pass", "fail", "incomplete"}
):
checks_segments.append((f" ({sub_checks} sub-checks)", MUTED))
if count["fail"]:
checks_segments += [(" · ", FAINT), (f"{count['fail']} failed", f"bold {RED}")]
if count["incomplete"]:
checks_segments += [(" · ", FAINT), (f"{count['incomplete']} didn't run", f"bold {RED}")]
if count["skipped"]:
checks_segments += [(" · ", FAINT), (f"{count['skipped']} skipped", MUTED)]
if warnings:
checks_segments += [(" · ", FAINT), (f"{warnings} warning{'s' if warnings != 1 else ''}", MUTED)]
rows.append(TierRow("summary" if lineup else "checks", checks_segments))
Expand Down Expand Up @@ -1213,8 +1224,10 @@ def summarize_tier1(results: list[ValidationResult], lineup: list[str] | None =
TierRow("quality", [(grade, f"bold {grade_style(grade, status=status)}"), (f" {score:.1f} / 100", TEXT)])
)
items = [_tier1_fix(r) for r in broken]
if incomplete:
items.append(_setup_fix(incomplete))
if setup := [r for r in incomplete if not _only_llm_stages_missing(r)]:
items.append(_setup_fix(setup))
if llm := [r for r in incomplete if _only_llm_stages_missing(r)]:
items.append(_llm_fix(llm))
return not failed, rows + fix_section_rows(items)


Expand Down Expand Up @@ -1259,6 +1272,83 @@ def _setup_fix(results: list[ValidationResult]) -> FixItem:
return FixItem("setup", problem, [*actions, f"or skip it: --skip {skip}"])


def _only_llm_stages_missing(result: ValidationResult) -> bool:
"""True when the check itself ran and only its ``--llm`` / ``--llm-verify`` stage did not.

``skillspector-llm`` is also recorded when SkillSpector is missing or its baseline is
rejected, before any scan runs; only a recorded SkillSpector version shows its static
scan completed.
"""
scans = result.incomplete_scans
if not scans or not all(s.endswith("-llm") or s.startswith("llm-") for s in scans):
return False
return "skillspector-llm" not in scans or "skillspector" in result.scanners


def _llm_fix(results: list[ValidationResult]) -> FixItem:
"""One item for checks whose LLM stage could not run: a missing key or a failed provider call."""
checks = ", ".join(dict.fromkeys(_short_name(r.validator_name) for r in results))
scans = {s for r in results for s in r.incomplete_scans}
flags = " / ".join(
f for f, on in (("--llm", "skillspector-llm" in scans), ("--llm-verify", "llm-verification" in scans)) if on
)
# SkillSpector reads its own provider settings when SKILLSPECTOR_PROVIDER names an adapter, so the
# public provider matters only for the other stages.
direct = _skillspector_adapter_fix() if "skillspector-llm" in scans else None
parts = [direct] if direct else []
if direct is None or "llm-verification" in scans:
reason, fixes = _public_provider_fix()
parts.append((f"--llm-verify: {reason}" if direct else reason, fixes))
reasons = "; ".join(reason for reason, _ in parts)
actions = [action for _, fixes in parts for action in fixes]
return FixItem(
"setup", f"{checks} LLM review didn't run: {reasons}", [*actions, f"or rerun without {flags or '--llm'}"]
)


def _public_provider_fix() -> tuple[str, list[str]]:
"""The problem and actions for the provider behind ``SKILL_EVAL_LLM_*``: a missing key or a failed call."""
from skillevaluator.provider_config import resolve_llm_provider

try:
resolve_llm_provider()
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved
except ValueError as exc:
reason, *setup = str(exc).splitlines() or [""]
reason = reason.rstrip(".")
exports = [line.strip().removeprefix("export ") for line in setup if line.strip().startswith("export ")]
# Some errors name the accepted keys without an export line ("OPENAI_API_KEY or SKILL_EVAL_LLM_API_KEY ...").
keys = list(dict.fromkeys(re.findall(r"\b[A-Z][A-Z0-9_]*_KEY\b", reason)))
if exports:
return reason, [f"export {' '.join(exports)}"]
if keys:
return reason, [f"{'or ' if i else ''}export {key}='your-api-key'" for i, key in enumerate(keys)]
return reason, ["set up an LLM provider and key, then rerun"]
return "the LLM provider call failed", [
"check the key and model with: skillevaluator doctor --tier 2 --verify-models"
]


def _skillspector_adapter_fix() -> tuple[str, list[str]] | None:
"""The problem and actions for a failed SkillSpector LLM stage when ``SKILLSPECTOR_PROVIDER`` names its adapter.

``None`` when it does not: SkillSpector then runs on the provider bridged from ``SKILL_EVAL_LLM_*``.
"""
from skillevaluator.validators.security import _SKILLSPECTOR_EXPLICIT_PROVIDER_ENV

adapter = os.environ.get("SKILLSPECTOR_PROVIDER", "").strip().lower()
if adapter not in _SKILLSPECTOR_EXPLICIT_PROVIDER_ENV:
return None
key = next(
(name for name in sorted(_SKILLSPECTOR_EXPLICIT_PROVIDER_ENV[adapter]) if name.endswith("_API_KEY")), None
)
if key is not None and not os.environ.get(key, "").strip():
return f"{key} is not set for SKILLSPECTOR_PROVIDER={adapter}", [f"export {key}='your-api-key'"]
credentials = key or "your AWS credentials"
return f"SkillSpector's {adapter} provider call failed", [
f"check {credentials} and SKILLSPECTOR_MODEL for SKILLSPECTOR_PROVIDER={adapter}"
]


def _skip_name(validator_name: str) -> str:
"""The ``--skip`` value that leaves out the check producing *validator_name*."""
if validator_name == "Secrets Detection":
Expand Down
Loading
Loading