Skip to content

Responsible AI: output contract, program dashboard and AI-BOM cross-check (#131) - #208

Merged
vsn411 merged 5 commits into
secfoo-com:mainfrom
Shruti070107:feat/responsible-ai-contract-dashboard-131
Nov 29, 2026
Merged

vsn411 merged 5 commits into
secfoo-com:mainfrom
Shruti070107:feat/responsible-ai-contract-dashboard-131

Conversation

@Shruti070107

@Shruti070107 Shruti070107 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #131.

What changed

  • Adds RESPONSIBLE_AI_OUTPUT_CONTRACT for responsible-ai-compliance, registered in SKILL_OUTPUT_CONTRACTS. The report now asks for an AI System Profile, a seven-row Dimension Coverage table, a Findings Register with Dimension / optional Framework instead of CWE / verdict, detailed ### [SEVERITY] Fn: blocks, a remediation roadmap and coverage notes. The skill text tells the agent to mark no-finding dimensions adequate with evidence and to stop emitting CWE IDs.
  • Adds a pure parser (src/secfoo/report/responsible_ai.py) for the profile, dimension rows, dimension/framework/stakes-tagged findings and the overall rating. Legacy CWE-shaped reports still yield findings and a rating, but their CWE column is never mislabelled as a dimension.
  • Persists runs.overall_rating, rai_dimensions and rai_findings in the same transaction as complete_run(). Adds a one-time migration that backfills the rating from stored reports. Badges and count_assessments_with_responsible_ai_risk() now read the stored column, so page loads no longer open N report files; a missing report file no longer un-rates an assessment.
  • Replaces the activity page's generic SAST-shaped cards with a dedicated dashboard when contract-shaped data exists: coverage, dimension × project heat map, stakes tier per system, open findings by dimension, framework mapping and AI-BOM mismatches. A fuller /activities/responsible-ai-compliance/dimensions view carries evidence and complete finding text. Legacy reports still show the generic cards until a contract-shaped run exists.
  • Adds moderate/low risk counts and a per-row dimensions link to /responsible-ai.
  • Includes attached AI-BOM items in the run brief as reference data and shows the code-vs-BOM diff on both the assessment page and the dashboard.
  • Documents the dashboard in docs/REFERENCE.md with a real screenshot of the seeded page (docs/assets/responsible-ai-dashboard.png).

Tests

  • New parser tests using a contract-shaped fixture, including legacy fallback and case-insensitive AI-BOM name comparison.
  • New storage tests for structured persistence, stored-rating badge behavior, migration backfill and assessment deletion with RAI evidence retained.
  • New web/end-to-end tests for the dashboard, dimension page, moderate-risk counts and the assessment AI-BOM cross-check.
  • Updated the legacy end-to-end test to assert that a deleted report file keeps the stored rating.

Targeted RAI, storage and assessment suites pass. The repository's pre-existing Python 3.14 baseline failures are unchanged by this PR.

Screenshot

Responsible AI program dashboard

@Shruti070107
Shruti070107 requested a review from vsn411 as a code owner November 27, 2026 19:04

@vsn411 vsn411 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and welcome! This covers every part of #131:

  • the contract;
  • a pure parser that falls back for legacy reports;
  • the stored rating with a backfill migration, so the badge no longer opens N files per page load;
  • the dashboard and dimension view;
  • the AI-BOM diff;
  • docs with a real screenshot.

The parser is careful too: an unknown status is skipped, never promoted to "adequate", and the CWE column of a legacy report is never read as a dimension. Templates use autoescaping, with no |safe on report text.

Two changes before we merge:

  1. A repeated finding ID turns a successful run into a crash. rai_findings has UNIQUE (run_id, finding_ref), but extract_findings doesn't deduplicate register rows. Models do sometimes repeat a row, or write a second register table. When that happens, the insert raises IntegrityError inside complete_run's with self._conn:. That rolls back the run's own UPDATE (status, report path, counts, cost). The runner's except BaseException then marks the run crashed and re-raises, so a scan that succeeded and was paid for is recorded as a crash. Please do both:

    • deduplicate by finding ID in extract_findings, keeping the first, the way extract_dimension_coverage already does with seen;
    • treat the RAI rows as best-effort. Use INSERT OR IGNORE, or a savepoint that logs and drops the RAI rows on error, so a parse problem can never lose the run row.

    Please add a test with a register that repeats F1.

  2. The AI-BOM section goes to every skill. ai_bom_section is set on the shared TargetContext, so on an assessment with a BOM, SAST, secret scanning and the rest also get the block. They also get "In the AI System Profile, name models…", a section their contracts don't have. That costs tokens and can confuse their output. Please add it only when the skill's output type is responsible-ai-compliance, as #131 describes.

Nit, fine to leave: _backfill_responsible_ai_ratings runs on every repository open. A run whose report has no rating stays NULL and is re-read each time. Storing a sentinel such as '' for "checked, no rating" would make it truly one-time.

CI hasn't run yet because this is your first PR here. A maintainer will approve the workflow run.

- Dedupe Responsible AI finding IDs before persistence and write RAI rows best-effort (savepoint + INSERT OR IGNORE) so a repeated F1 cannot roll back a successful, paid-for run.
- Render the AI-BOM brief only for the responsible-ai-compliance output type, including custom skills that reuse it.
- Store an empty rating sentinel for parsed RAI reports with no rating so badges and the backfill migration never re-open those files.
- Add parser, storage, renderer, runner and end-to-end regressions; update the /responsible-ai info-tip expectations for the new risk cards.
@Shruti070107

Copy link
Copy Markdown
Contributor Author

Thanks @vsn411 — addressed both review points in 8f09fff (rebased on the latest main merge):

  1. Repeated finding ID / failed run — extract_findings() now deduplicates register rows by ID, keeping the first. RAI rows are written best-effort in a savepoint with INSERT OR IGNORE, so a duplicate F1 or any malformed row is logged and dropped without rolling back the run's successful UPDATE. Added regressions at the parser, storage and CLI end-to-end levels for a register that repeats F1.

  2. AI-BOM brief scope — TargetContext.ai_bom_section is now included in a prompt only when the skill's output_type is responsible-ai-compliance (custom skills reusing that contract included). SAST, secret scanning and the other skills no longer receive the AI System Profile instructions. Covered by renderer, runner and end-to-end tests.

I also took the nit: parsed RAI reports with no rating store '', so the backfill migration and badge path never re-open those report files. Updated the /responsible-ai info-tip expectations for the new moderate/low risk cards added by this PR, and fixed the ruff errors surfaced by the newly blocking CI lint check.

233 targeted tests pass and ruff check . is clean. Ready for another look — CI may need a maintainer to approve the first-time-contributor workflow run.

Only ? placeholders and the constant _LATEST_RAI_RUN fragment are
interpolated; bandit is now blocking in CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vsn411

vsn411 commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the quick, thorough follow-up. Both review points are fixed exactly as needed:

  • finding IDs are deduplicated, and the RAI rows go in through a savepoint with INSERT OR IGNORE, so a parse problem can't lose the run row;
  • the AI-BOM block is limited to the Responsible AI output type.

The '' sentinel for "checked, no rating" is a nice touch too.

Since #206, bandit runs as a blocking CI step. It flagged three B608 "string-built SQL" false positives in repository.py: the IN (?,?,…) placeholders and the constant _LATEST_RAI_RUN fragment. I pushed one commit (667e3e0) that annotates them with # nosec B608 and the reason. Nothing else changed.

Once a maintainer approves the workflow run and CI is green, this is ready to merge.

Comment on lines +16 to +18
from secfoo.report.sast import (
SKILL_ID, # noqa: F401 -- re-exported: routes/activities.py uses sast_dashboard.SKILL_ID
)
Comment thread tests/test_runner.py
renderer must gate it by the skill's output type rather than letting
SAST, secret scanning and the rest pay for an irrelevant brief.
"""
import secfoo.runner

@vsn411 vsn411 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both review points are addressed (deduplicated finding IDs with a savepoint, AI-BOM limited to Responsible AI). CI is green. Approving.

@vsn411
vsn411 merged commit 4a4e58f into secfoo-com:main Nov 29, 2026
16 checks passed
@vsn411

vsn411 commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Merged, thank you, and congratulations on your first contribution to secfoo! 🎉 Responsible AI now has a real contract, stored ratings and its own program dashboard, which closes #131.

Before merging I added the # nosec B608 annotations and merged current main. CI was green on all required checks.

@github-actions

Copy link
Copy Markdown

Leaderboard update

Shruti070107 now has 10 points (rank #8). 15 more to reach Bronze.

Full leaderboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants