Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(modelarmor): created samples for model armor #13187

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mihirvala-crestdata
Copy link

@mihirvala-crestdata mihirvala-crestdata commented Feb 25, 2025

Description

Added more Model Armor code samples for following use cases:

Quickstart

Create a template and sanitize user prompt and model response using it.

Floor Settings

Get Floor Settings of given Folder, Organization & Project
Update Floor Settings of given Folder, Organization & Project
Disable Floor Settings of given Folder, Organization & Project


Template CRUD

Create a template with labels
Create Template with template metadata
Create a template with Basic Sensitive Data Protection configuration
Create a template with Advanced Sensitive Data Protection configuration

List all available templates in given project and location
List all available templates with filter in given project and location
 
View template with given template_id
 
Update template configuration for given template_id
Update template with Mask Configuration
Update template metadata
Update labels of a template
 
Delete template with given template_id


User Prompt Sanitization

Sanitize the user prompt based on the given template configuration
Scan a PDF file based on the given template configuration


Model Response Sanitization

Sanitize the model response based on the given template configuration
Sanitize the model response along with user prompt


Checklist

@mihirvala-crestdata mihirvala-crestdata requested review from a team as code owners February 25, 2025 18:12
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Feb 25, 2025
Copy link

snippet-bot bot commented Feb 25, 2025

Here is the summary of changes.

You are about to add 24 region tags.
You are about to delete 6 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@vipul7499 vipul7499 added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Feb 27, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Feb 27, 2025
@vipul7499 vipul7499 added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Feb 28, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Feb 28, 2025
@vipul7499 vipul7499 added kokoro:force-run Add this label to force Kokoro to re-run the tests. kokoro:run Add this label to force Kokoro to re-run the tests. labels Feb 28, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Feb 28, 2025
@glasnt glasnt added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 6, 2025
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 6, 2025
@glasnt glasnt requested a review from a team March 7, 2025 04:41
Copy link
Contributor

@glasnt glasnt left a comment

Choose a reason for hiding this comment

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

Approved from the "tests pass and follows styleguide" standpoint. Team added to repo, so CODEOWNERS is now valid.

However, this needs subject matter expert approval (from @GoogleCloudPlatform/cloud-modelarmor-team who I have manually assigned to this PR, since this PR adds the automation that would assign them automatically)

Do not merge until subject matter approval has been done.

@glasnt glasnt added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 7, 2025
assert template_id in str(templates)


def test_user_prompt(

Choose a reason for hiding this comment

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

This looks like a generic use case of testing user prompt. We should add 1 test case per each filter i.e. a case where malicious_uri is filtered, a case where some pi_jb attempt is filtered, etc.

Suggestion -
There should be 2 templates - empty_template with empty filter config (i.e. all filters disabled) and all_filters_template with all filters enabled. Then test for each filter against both templates -> assert that MATCH_FOUND = false for empty_template and MATCH_FOUND = true for all_filters_template.

Choose a reason for hiding this comment

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

Added test cases for screening test cases along with existing screening test cases.

  • user prompt screening with empty filter template
  • user prompt screening with all filter template
  • test_sanitize_model_response_with_empty_template
  • test_sanitize_model_response_with_user_prompt_with_empty_filters

Also added individual assertion if specific filter match is expected.

Choose a reason for hiding this comment

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

I see that you have added cases where rai (dangerous) and malicious_uri filters result in MATCH_FOUND. What about rai (other sub filters - hate_pseech, sexually_explicit, harrasment) & pi_and_jailbreak cases? Please add those as well. Also add cases for csam, this filter result is returned in every response irrespective of the template filter_config.

)

# Define the prompt.
user_prompt = (

Choose a reason for hiding this comment

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

This should also come an an input argument to the method.

Choose a reason for hiding this comment

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

Same for sanitize_model_response as well.

assert template_id in str(templates)


def test_user_prompt(

Choose a reason for hiding this comment

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

I see that you have added cases where rai (dangerous) and malicious_uri filters result in MATCH_FOUND. What about rai (other sub filters - hate_pseech, sexually_explicit, harrasment) & pi_and_jailbreak cases? Please add those as well. Also add cases for csam, this filter result is returned in every response irrespective of the template filter_config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Indicates a pull request not ready for merge, due to either quality or timing. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants