fix: Support escaped curly braces in instruction templates

Close #3527

Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 868875061
This commit is contained in:
George Weale
2026-02-11 15:38:53 -08:00
committed by Copybara-Service
parent 34da2d5b26
commit 079f7a38be
2 changed files with 1 additions and 51 deletions
@@ -146,32 +146,6 @@ async def test_inject_session_state_with_invalid_state_name_returns_original():
assert populated_instruction == "Hello {invalid-key}!"
@pytest.mark.asyncio
async def test_inject_session_state_with_escaped_braces_returns_literal():
instruction_template = "Code sample: {{user_name}}. Value: {user_name}."
invocation_context = await _create_test_readonly_context(
state={"user_name": "Foo"}
)
populated_instruction = await instructions_utils.inject_session_state(
instruction_template, invocation_context
)
assert populated_instruction == "Code sample: {user_name}. Value: Foo."
@pytest.mark.asyncio
async def test_inject_session_state_with_escaped_non_placeholder_keeps_double_braces():
instruction_template = "Literal template: {{'key2': 'value2'}}."
invocation_context = await _create_test_readonly_context(
state={"user_name": "Foo"}
)
populated_instruction = await instructions_utils.inject_session_state(
instruction_template, invocation_context
)
assert populated_instruction == "Literal template: {{'key2': 'value2'}}."
@pytest.mark.asyncio
async def test_inject_session_state_with_invalid_prefix_state_name_returns_original():
instruction_template = "Hello {invalid:key}!"