Sandbox nested persona template rendering in evaluation prompts#5266
Open
petrmarinec wants to merge 2 commits intogoogle:mainfrom
Open
Sandbox nested persona template rendering in evaluation prompts#5266petrmarinec wants to merge 2 commits intogoogle:mainfrom
petrmarinec wants to merge 2 commits intogoogle:mainfrom
Conversation
Author
|
For clarity, I also reran the remaining failing full-suite tests on unmodified The only full-suite failures I saw were these 5
Those same 5 failures reproduce on unmodified |
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
Nested persona behavior strings were rendered through
render_string_filter, which created a fresh Jinja template from persona-controlled content instead of consistently reusing a sandboxed environment. That allowed nested persona templates to execute outside the intended sandbox boundary in evaluation prompt construction.Affected files:
src/google/adk/evaluation/simulation/llm_backed_user_simulator_prompts.pysrc/google/adk/evaluation/simulation/per_turn_user_simulator_quality_prompts.pySolution:
Render nested persona strings through
SandboxedEnvironmentand useSandboxedEnvironmentfor the per-turn evaluator prompt builder as well. This keeps supported nested placeholders such as{{ stop_signal }}working while blocking unsafe nested template access. Added regression tests for both the safe interpolation path and blocked unsafe attribute traversal.Testing Plan
Unit Tests:
Passed in clean Linux Docker (
python:3.11-bookworm):uv sync --all-extraspytest tests/unittests/evaluation/simulation70 passedAdditional repo-wide validation:
pytest tests/unittests5326 passed, 1 skipped, 5 failedorigin/maintests/unittests/tools/test_skill_toolset.pyintegration timeoutsManual End-to-End (E2E) Tests:
adk webregression test against the eval API in Linux Docker using a local non-LLM root agent.{{ ''.__class__.__mro__ }}was blocked during prompt construction withjinja2.exceptions.SecurityError.{{ stop_signal }}placeholders did not raiseTemplateSyntaxErrororSecurityErrorand progressed beyond prompt rendering into a real Gemini model call.429 RESOURCE_EXHAUSTED, but the absence of template errors and the subsequent model call confirm the sandboxed nested rendering path is functioning as intended.Checklist
Additional context
This is a small, focused fix intended to close the nested-template sandbox bypass path without changing the supported nested placeholder behavior used by existing personas.