Skip to content

feat: add tests for guardrails with huggingface detectors#369

Merged
dbasunag merged 4 commits intoopendatahub-io:mainfrom
adolfo-ab:guardrails-hf-detectors
Jun 26, 2025
Merged

feat: add tests for guardrails with huggingface detectors#369
dbasunag merged 4 commits intoopendatahub-io:mainfrom
adolfo-ab:guardrails-hf-detectors

Conversation

@adolfo-ab
Copy link
Copy Markdown
Contributor

@adolfo-ab adolfo-ab commented Jun 20, 2025

This PR adds a new test class with tests for the GuardrailsOrchestrator paired with HuggingFace detectors.

Description

These tests verify that the GuardrailsOrchestrator works as expected when using HuggingFace detectors
Steps:
- Deploy an LLM (Qwen2.5-0.5B-Instruct) using the vLLM SR.
- Deploy the GuardrailsOrchestrator.
- Deploy a prompt injection detector using the HuggingFace SR.
- Check that the detector works when we have an unsuitable input.
- Check that the detector works when we have a harmless input (no detection).

Also includes some utils functions and minor improvements.

How Has This Been Tested?

Running on PSI.

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 20, 2025

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for testing prompt injection detection using Hugging Face-based detectors alongside built-in detectors.
    • Introduced new test scenarios and fixtures to validate multiple detector backends and configurations.
  • Bug Fixes

    • Improved clarity and consistency in test input naming and payload construction.
  • Tests

    • Expanded test coverage to include prompt injection detection and multiple detector orchestration setups.
    • Updated test payload helper functions and improved test structure for maintainability.
  • Chores

    • Updated model and image references to newer versions for improved compatibility and performance.

Walkthrough

The changes extend and modularize test fixtures and test classes for the Guardrails Orchestrator to support both built-in and Hugging Face detectors. New fixtures, routes, and runtime support are introduced for Hugging Face-based detectors, and the test suite is expanded to cover prompt injection detection scenarios with improved payload handling.

Changes

File(s) Change Summary
tests/model_explainability/guardrails/conftest.py Refactored and extended fixtures to support both built-in and Hugging Face detectors, added new configmaps, inference service, runtime, and route fixtures for prompt injection detection.
tests/model_explainability/guardrails/test_guardrails.py Updated tests to use new payload helper, improved input naming, added tests for Hugging Face detectors, and expanded negative/positive detection scenarios.
tests/model_explainability/guardrails/utils.py Replaced get_chat_payload with get_chat_detections_payload to support detectors and additional payload parameters.
tests/model_explainability/lm_eval/conftest.py Updated model identifier in lmevaljob_hf fixture from "Qwen/Qwen2.5-0.5B" to "Qwen/Qwen2.5-0.5B-Instruct".
utilities/constants.py Updated image reference for QWEN_MINIO_CONFIG in the MinIo.PodConfig class.

Possibly related PRs

Suggested labels

Verified, lgtm-by-mwaykole, lgtm-by-dbasunag, ModelServing

Suggested reviewers

  • mwaykole
  • sheltoncyril
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/hold', '/wip', '/cherry-pick', '/lgtm', '/verified', '/build-push-pr-image'}

@adolfo-ab adolfo-ab changed the title wip: test for guardrails with huggingface detectors feat: add tests for guardrails with huggingface detectors Jun 25, 2025
@adolfo-ab adolfo-ab force-pushed the guardrails-hf-detectors branch from 94b28e4 to 7c5a058 Compare June 25, 2025 12:04
@adolfo-ab adolfo-ab marked this pull request as ready for review June 25, 2025 12:05
@adolfo-ab adolfo-ab requested a review from a team as a code owner June 25, 2025 12:05
@adolfo-ab
Copy link
Copy Markdown
Contributor Author

/verified

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db67d52 and 7c5a058.

📒 Files selected for processing (5)
  • tests/model_explainability/guardrails/conftest.py (8 hunks)
  • tests/model_explainability/guardrails/test_guardrails.py (7 hunks)
  • tests/model_explainability/guardrails/utils.py (1 hunks)
  • tests/model_explainability/lm_eval/conftest.py (1 hunks)
  • utilities/constants.py (1 hunks)
🧰 Additional context used
🪛 Pylint (3.3.7)
tests/model_explainability/guardrails/test_guardrails.py

[refactor] 156-156: Too many arguments (7/5)

(R0913)


[refactor] 156-156: Too many positional arguments (7/5)

(R0917)


[refactor] 201-201: Too many arguments (8/5)

(R0913)


[refactor] 201-201: Too many positional arguments (8/5)

(R0917)


[refactor] 229-229: Too many arguments (8/5)

(R0913)


[refactor] 229-229: Too many positional arguments (8/5)

(R0917)

🔇 Additional comments (4)
utilities/constants.py (1)

274-274: LGTM!

The MinIO image update to support HuggingFace LLM models aligns with the PR's objective.

tests/model_explainability/guardrails/utils.py (1)

15-41: Well-structured enhancement to support detector configurations!

The new get_chat_detections_payload function properly extends the payload construction with model and detector support, maintaining clear typing and documentation.

tests/model_explainability/lm_eval/conftest.py (1)

38-38: Good choice using the instruction-tuned model variant!

The Qwen2.5-0.5B-Instruct model is more appropriate for this fixture since it includes system instructions and chat templates.

tests/model_explainability/guardrails/test_guardrails.py (1)

1-249: Excellent test coverage for both detector backends!

The test suite properly validates both built-in regex and HuggingFace prompt injection detectors with appropriate positive and negative test cases. The static analysis warnings about too many arguments can be safely ignored as they're standard for pytest fixtures.

Copy link
Copy Markdown
Contributor

@kpunwatk kpunwatk left a comment

Choose a reason for hiding this comment

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

PR lgtm!

@dbasunag dbasunag merged commit 906091d into opendatahub-io:main Jun 26, 2025
13 checks passed
@github-actions
Copy link
Copy Markdown

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants