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
@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
getattrwith a constant attribute name, resolving the Ruff B009 lint warning. test_llama_guard_output_action_metadata_is_registration_onlymay 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 accessllama_guard_check_output.action_meta, or - Remove
test_llama_guard_output_action_metadata_is_registration_onlyif it is deemed redundant with other action-registration-metadata coverage.
- Replace
- No new Ruff/lint warnings introduced.
- Existing test suite continues to pass.
References
- PR: https://github.com/NVIDIA-NeMo/Guardrails/pull/2151
- Review comment: https://github.com/NVIDIA-NeMo/Guardrails/pull/2151#discussion_r3585336541
- Requested by: @Pouyanpi
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.