NVIDIA-NeMo / NVIDIA-NeMo/Guardrails

chore: clean up getattr usage / drop test_llama_guard_output_action_metadata_is_registration_only in tests/test_llama_guard.py

Open
#2,173 0 comments 0 reactions 1 assignee View on GitHub

@Pouyanpi is already working on this.

Since Jul 15, 2026.

Dominant language
Python
Stars
7.2k
Forks
843
Avg merge
3d 1h
Merged PRs (30d)
25

Description

Summary

In tests/test_llama_guard.py, the test test_llama_guard_output_action_metadata_is_registration_only uses getattr(llama_guard_check_output, "action_meta") to inspect the registration metadata of the llama_guard_check_output action.

This pattern was flagged by static analysis (Ruff B009 — "Do not call getattr with a constant attribute value") since @action() always assigns the action_meta attribute, so direct attribute access (llama_guard_check_output.action_meta) would be safe and idiomatic.

During review of PR #2151, it was agreed that this is pre-existing behavior and out of scope for that PR, and that the test itself should eventually be dropped rather than just fixed for style.

Rationale

  • Removes reliance on getattr with a constant attribute name, resolving the Ruff B009 lint warning.
  • test_llama_guard_output_action_metadata_is_registration_only may no longer be needed once the underlying registration-metadata contract is validated elsewhere (e.g., via shared action-registration tests), so removing/replacing it should be considered rather than just patching the lint issue.

Affected areas

  • tests/test_llama_guard.py

Acceptance criteria

  • Either:
    • Replace getattr(llama_guard_check_output, "action_meta") with direct attribute access llama_guard_check_output.action_meta, or
    • Remove test_llama_guard_output_action_metadata_is_registration_only if it is deemed redundant with other action-registration-metadata coverage.
  • No new Ruff/lint warnings introduced.
  • Existing test suite continues to pass.

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.