feat(samples): add samples for the context filter, Model Armor and BigQuery analytics plugins - #7262
Open
vishal-bulbule wants to merge 3 commits into
Open
vishal-bulbule wants to merge 3 commits into
vishal-bulbule wants to merge 3 commits into
Conversation
There was no sample for ContextFilterPlugin. This one keeps the two most recent invocations and prints how many contents each request carries, so the effect and its trade-off are both visible in the output.
There was no runnable sample for ModelArmorPlugin. This one screens input and output against a Model Armor template and sends a prompt-injection attempt, so the blocked path is visible and not just described.
There was no runnable sample for the BigQuery analytics plugin. This one logs a two-turn run with a tool call and shows the query that reads the events back, plus how a script should release the shared background transport.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Problem:
contributing/samples/plugins/has samples for the basic plugin pattern,DebugLoggingPluginandReflectAndRetryToolPlugin. Three prebuilt plugins that people are likely to reach for have norunnable sample:
ContextFilterPlugin,ModelArmorPluginandBigQueryAgentAnalyticsPlugin.For the Model Armor plugin in particular, the guide describes the behaviour but there is nothing
to run, so the blocked path is never actually seen.
Solution:
Three samples, following the layout of the existing ones (
plugin_<name>/with__init__.py,main.pyand aREADME.md):plugin_context_filter: keeps the two most recent invocations. A small counter plugin in thesample prints how many contents each request carries, registered after the filter so it sees
the trimmed request. The README notes the trade-off: the model can only answer from what it
still sees.
plugin_model_armor: screens input and output against a Model Armor template and sends aprompt-injection attempt, so the blocked message and the fail-closed setting are visible.
plugin_bigquery_agent_analytics: logs a two-turn run with a tool call, shows the query thatreads the events back, and shows how a short script should release the shared background
transport.
Each README shows the real output of the run, not an illustration.
Testing Plan
Unit Tests:
No test files were added.
test_samples.pydiscovers samples automatically, so each of the three is covered bytest_sample_loadswithout any test file of its own:No recorded-session replay tests (
tests/*.json) were added; happy to add them if you wouldlike these samples covered that way too.
Manual End-to-End (E2E) Tests:
Each sample was run against real services on
gemini-2.5-flash.plugin_context_filter, no cloud setup needed:The request stops growing while the session keeps every event.
plugin_model_armor, against a template with the prompt injection and jailbreak filterenabled:
The plugin logged
Model Armor input sanitization match foundfor the second prompt.plugin_bigquery_agent_analytics, against a real dataset. Reading the events back:pre-commit run --filespasses on all nine files.Checklist
Additional context
ContextFilterPluginandBigQueryAgentAnalyticsPluginare imported from their modules becausethey are not exported from
google.adk.plugins, unlikeLoggingPluginandReflectAndRetryToolPlugin. Happy to switch those imports if the exports are added.