Skip to content

docs: fix the filter that silences the auroc_confidence_metric warning - #504

Open
pcbeingused33 wants to merge 16 commits into
awslabs:devfrom
pcbeingused33:c0792-docs-warning-filter
Open

pcbeingused33 wants to merge 16 commits into
awslabs:devfrom
pcbeingused33:c0792-docs-warning-filter

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #493

Description of Changes

The documented AUROC warning recipe now filters by message rather than the comparison engine module. It includes Python and pytest configuration forms for both the legacy AUROC DeprecationWarning and the single-document confidence UserWarning.

A filter installed at module import time is overridden by pytest's per-test filters; installing it inside a test or fixture also works. The wording avoids relying on the warning's stacklevel attribution or frequency. A CHANGELOG.md entry is included.

Testing

The three warning-filter tests pass. Their assertion checks that neither documented message is recorded while allowing unrelated warnings. An additional probe injecting an unrelated warning failed before this follow-up and passes afterward. Filter constants point to the corresponding documentation section.

Additional Notes

This PR was prepared with assistance from AI coding agents (Claude Code and Codex).

The documented filter matched module comparison_engine, but the warning
is attributed to structured_model.py, so it never silenced anything.
Filter by message instead, and drop the 'already migrated' framing: the
warning fires on any compare_with(add_confidence_metrics=True) call.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@sromoam sromoam self-assigned this Nov 4, 2026

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, @pcbeingused333! This is a real improvement. The message= filter does match the warning, which the old module= filter never did, and the diagnosis in your description is spot on. A few things still need to change before this fully fixes #493.

Needs changes

  1. Add the pytest form. Under pytest, a module-level warnings.filterwarnings("ignore", ...) doesn't silence the warning. pytest wraps each test in its own warnings context and shows DeprecationWarnings regardless. Most users see this warning in their test suite, so please give the config form next to the code form, for example:

    [tool.pytest.ini_options]
    filterwarnings = [
        "ignore:The 'auroc_confidence_metric' result key is deprecated:DeprecationWarning",
    ]
  2. Remove the sentence saying the warning is attributed to structured_model.py (around :141). That attribution is a bug in how the warning is raised (its stacklevel), not intended behaviour. Once that bug is fixed, the sentence would be wrong. The message= advice stands without it.

  3. Correct "once per process" (:129). With Python's default filters the warning isn't shown at all, because it's attributed to library code. Under -W error or pytest's filterwarnings = error, it raises on every call, not just the first. Saying "emits a DeprecationWarning" without the frequency is accurate.

  4. Mention the second warning. The same add_confidence_metrics=True call also emits a UserWarning ("Single-document confidence metrics are a quick sanity check..."). A reader who applies your filter will still see that one and think the recipe is broken. One sentence naming it, with its own message= filter, would cover it.

  5. Add a CHANGELOG entry under [Unreleased], since people pasted the old filter and it never worked (see RELEASING.md).

Would be great, but optional: a test that installs the documented filter and asserts no DeprecationWarning is recorded from compare_with(add_confidence_metrics=True). That would stop the recipe from silently breaking again when the message changes.

The stacklevel bug itself is out of scope here. We'll track it in a separate issue, so please don't feel you need to fix it in this PR.

Also, a heads-up: #525 targets the same issue. Whichever lands first, we'll close the other, so it's worth a quick look to avoid duplicate effort.

On timing: I'm away until Tuesday, November 10, so my next review will be after that. Thanks again!

@sromoam

sromoam commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

As mentioned in the review, the stacklevel bug is now tracked in #541. Nothing to do for it in this PR.

Add the pytest filterwarnings form, drop the structured_model.py
attribution and the 'once per process' claim, document the second
UserWarning with its own filter, add a CHANGELOG entry and a test that
the documented filters silence both warnings.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Thanks for the review, all points addressed in 81e87cf:

  1. Added the pytest form (filterwarnings in pyproject.toml) next to the warnings.filterwarnings snippet, since the latter does not silence the warning under pytest.
  2. Removed the sentence attributing the warning to structured_model.py.
  3. Corrected the "once per process" wording: with no filter it is shown once, and under -W error it raises every time.
  4. Documented the second UserWarning ("Single-document confidence metrics ...") with its own message= filter.
  5. Added a CHANGELOG.md entry under [Unreleased], and a test (tests/test_confidence_warning_filter.py) checking that the documented filters silence both warnings.

The PR body's "No CHANGELOG entry" note is now outdated; the entry is in.

This comment was drafted with Claude Code.

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>

# Conflicts:
#	CHANGELOG.md

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you, @pcbeingused333, this is a really thorough follow-up! Every point from the last review is addressed, and the optional test is a great addition. Three small things before we merge:

  1. Narrow the pytest claim (around confidence-evaluation.md:141). Under pytest, only a filter set at module import time is overridden by pytest's per-test filters. A warnings.filterwarnings(...) call inside a test or a fixture works fine (we checked with a probe test). Something like "a filter set at module level does not apply under pytest; set it in a fixture, or use the filterwarnings config below" keeps readers away from a dead end without steering them off a fix that works.

  2. Add the pytest form for the UserWarning too (around :150). Right now it only has the Python form, just after the doc explains why the Python form isn't enough under pytest. One more line in the TOML block covers it, for example:

    "ignore:Single-document confidence metrics are a quick sanity check:UserWarning",
  3. Loosen the test assertion (tests/test_confidence_warning_filter.py:45). assert _recorded(AUROC, SINGLE_DOC) == [] fails if compare_with ever emits any unrelated warning. Please assert that neither of the two messages appears in the recorded warnings instead.

Optional, only if you have time:

  • The test copies the filter strings rather than reading them from the doc, so the two could drift apart. A comment pointing at the doc section would be enough.
  • tests/structured_object_evaluator/conftest.py already resets deprecation._warned automatically. Moving the test into tests/structured_object_evaluator/ (next to the existing deprecation tests in test_confidence_metrics.py) would let you drop the local fixture.
  • The PR description still says there's no CHANGELOG entry. A quick refresh would help the next reviewer.

Thanks again, this is very close!

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The pytest wording now distinguishes import-time filters from filters installed inside tests or fixtures, and the TOML example includes the separate UserWarning filter. The test now checks only the two documented message prefixes, so unrelated warnings do not fail it; a comment links the filter constants to the documentation section. All three warning-filter tests and an unrelated-warning probe pass. The refreshed description also records the existing CHANGELOG entry. The UserWarning paragraph now explicitly refers to the AUROC Python filter, since the TOML example already covers both warnings. The test stays at the top level of tests/ for now; happy to move it under tests/structured_object_evaluator/ and drop the local fixture if you prefer.

This response was drafted with Codex.

Signed-off-by: Alex Castillo <alex.castillog33@gmail.com>
@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The pytest wording now distinguishes import-time filters from filters installed inside tests or fixtures, and the TOML example includes the separate UserWarning filter. The test now checks only the two documented message prefixes, so unrelated warnings do not fail it; a comment links the filter constants to the documentation section. All three warning-filter tests and an unrelated-warning probe pass. The refreshed description also records the existing CHANGELOG entry. The UserWarning paragraph now explicitly refers to the AUROC Python filter, since the TOML example already covers both warnings. The test stays at the top level of tests/ for now; happy to move it under tests/structured_object_evaluator/ and drop the local fixture if you prefer.

This response was drafted with Codex.

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Hi, I believe the review feedback is addressed now. Could you take another look when you have a moment? Happy to adjust anything else. Thanks!

@digalaviz

Copy link
Copy Markdown
Contributor

Thanks! sromoam's three points look addressed: I measured the filters and they silence both warnings and nothing else. One fix before merging: 1.0.2 shipped since, so a merge puts the CHANGELOG entry under [1.0.2], which still has the old recipe. Could you move it to [Unreleased] → ### Documentation? Optional: assert on the message prefix in tests/test_confidence_warning_filter.py:43 and :54 too, as you did for point 3.

pcbeingused33 and others added 2 commits November 27, 2026 21:24
Signed-off-by: Alex <alex.castillog33@gmail.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Alex <alex.castillog33@gmail.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Done in faf35ae: merged dev and moved the CHANGELOG entry to [Unreleased] → ### Documentation. I also took the optional point, so both tests now assert on the message prefixes.

This comment was drafted with Claude Code.

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @pcbeingused33! Everything from both of my reviews is in, and so is Diego's CHANGELOG move. I ran the recipe exactly as the page shows it. Under python -W error, the two Python filters silence both warnings. Under pytest, the TOML block silences both. A module-level filter is overridden and a fixture filter works, just as the page now says. The old module= filter still fails to silence the warning, so the CHANGELOG line is accurate too. The full suite passes locally (6771 passed).

One optional touch: the other ### Documentation entries end with an issue link, so adding ([#493](https://github.com/awslabs/stickler/issues/493)) would match them.

Approving. Thanks for sticking with this one!

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-12-04T22:30:47+00:00
  • Time since scan: 3 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-12-04T22:27:02+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 0 0 0 8211 0 0 PASSED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 0 0 0 0 0 0 PASSED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 7 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Report generated by Automated Security Helper (ASH) at 2026-12-04T22:30:48+00:00

@sromoam sromoam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @pcbeingused33, one small thing turned up on a second pass, nothing that changes my approval. Merged with current dev (a3c6d9a), the merge is clean, the entry stays under [Unreleased], the old module= filter still fails, and the two message= filters and the TOML block still silence both warnings.

Smaller

  1. A session- or module-scoped fixture's filter lasts for one test only (docs/docs/Guides/Evaluation/confidence-evaluation.md:143). pytest restores the warning filters after every test, so a reader who installs the filters from an autouse scope="session" fixture in conftest.py gets the UserWarning back from the second test on. With filterwarnings = error and two tests that each call compare_with(add_confidence_metrics=True), a function-scoped fixture gives 2 passed; a session- or module-scoped one gives 1 passed, 1 failed on the UserWarning. Naming the scope covers it, suggestion inline.

One heads-up: we're not merging anything outside the 1.1.0 milestone until 1.1.0 lands, so this will wait until after that even though it's approved.

```

This is scoped to the comparison engine, so unrelated `DeprecationWarning`s from other libraries (or other parts of stickler) still surface.
Under pytest, a `warnings.filterwarnings(...)` call at module import time is overridden by pytest's per-test filters. Set the filter inside a test or fixture, or use the pytest configuration below (including the separate `UserWarning` filter explained next):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested wording, so readers don't reach for a session-scoped fixture:

Suggested change
Under pytest, a `warnings.filterwarnings(...)` call at module import time is overridden by pytest's per-test filters. Set the filter inside a test or fixture, or use the pytest configuration below (including the separate `UserWarning` filter explained next):
Under pytest, a `warnings.filterwarnings(...)` call at module import time is overridden by pytest's per-test filters. Set the filter inside a test or a function-scoped fixture (pytest restores the filters after each test, so a session- or module-scoped fixture covers only the first test in its scope), or use the pytest configuration below (including the separate `UserWarning` filter explained next):

pytest restores warning filters after each test, so a session- or
module-scoped fixture only covers the first test.

Signed-off-by: Alex <alex.castillog33@gmail.com>
@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Done in 8f404e6. The pytest paragraph now matches the suggestion: set the filter inside a test or a function-scoped fixture, because pytest restores the filters after each test and a session- or module-scoped fixture only covers the first test.

The warning-filter tests still pass. Noted that this stays out of the merge queue until 1.1.0.

This reply was drafted with Claude Code.

@sromoam sromoam added the anytime Non-breaking improvement off the release critical path: merge whenever it's ready label Dec 4, 2026

This branch has not been deployed

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

Labels

anytime Non-breaking improvement off the release critical path: merge whenever it's ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix the warnings filter that claims to silence the auroc_confidence_metric deprecation

3 participants