fix: escape ${expression} in formatString description to prevent ADK KeyError#1409
fix: escape ${expression} in formatString description to prevent ADK KeyError#1409brucearctor wants to merge 1 commit into
Conversation
…KeyError
The formatString function description in basic_catalog.json contained
the literal text ${expression}, which the ADK's inject_session_state()
regex (r'{+[^{}]*}+') matched as a template variable. Since 'expression'
passes Python's str.isidentifier() check, the ADK attempted to look it
up in the session state dict and raised a KeyError when not found.
Changed ${expression} to ${<expression>} so that '<expression>' fails
the isidentifier() check, causing the ADK to skip it (returning the
match as-is). The other interpolation examples in the description
(${/absolute/path}, ${now()}, etc.) were already safe because they
contain characters (/, parentheses) that make them invalid identifiers.
Fixes google#1388
|
Would it be possible to maybe escape the |
|
@ditman there might be other options, but I filed: google/adk-python#5706 I can work on that issue with the adk team to try to get that fix in place. This should be OK in the meantime? |
|
Thanks for fixing this! Yes, the fix LGTM, but let's have @nan-yu or @gspencergoog take a second look, I normally don't work on the python code (or the spec :P) |
|
It feels like this should be fixed in the ADK library. @gspencergoog has filed an issue against the ADK project: google/adk-python#5179. |
I think this is here too ? google/adk-python#5706 Or, should I then not address in favor of whoever doing 5179 ? |
Summary
Fixes #1388
The
formatStringfunction description inbasic_catalog.jsoncontained the literal text${expression}, which the ADK'sinject_session_state()matched as a template variable. Sinceexpressionpasses Python'sstr.isidentifier()check, the ADK raised aKeyErrorwhen it couldn't find it in the session state.Changes
Changed
${expression}→${<expression>}in theformatStringdescription for bothv0_9andv0_10catalog schemas.The angle brackets cause
<expression>to fail theisidentifier()check, so the ADK's_is_valid_state_name()returnsFalseand the match is returned as-is (line 108 ofinstructions_utils.py).Why only
${expression}was affectedThe other interpolation examples in the same description were already safe:
${/absolute/path}→/absolute/pathis not a valid identifier (contains/)${now()}→now()is not a valid identifier (contains())${relative/path}→relative/pathis not a valid identifier (contains/)Only
expressionwas a bare, valid Python identifier.Files changed
specification/v0_9/json/basic_catalog.jsonspecification/v0_10/json/basic_catalog.json