Repository navigation
MAINT: make PromptShield parser dispatch exhaustive - #3797
Slai.life (huong8373tt-beep) wants to merge 2 commits into
Conversation
Signed-off-by: Slai.life <huong8373tt@gmail.com>
| # Preserve the historical runtime fallback for an unknown value. | ||
| user_prompt = "" | ||
| documents = [] | ||
| split_input = input_str.split("<document>") | ||
|
|
||
| for element in split_input: | ||
| contents = element.split("</document>") | ||
|
|
||
| if len(contents) == 1: | ||
| user_prompt += contents[0] | ||
| else: | ||
| documents.append(contents[0]) | ||
| user_prompt += contents[1] | ||
|
|
||
| return {"userPrompt": user_prompt, "documents": documents if documents else []} | ||
|
|
||
| def _add_auth_param_to_headers(self, headers: dict[str, str]) -> None: |
There was a problem hiding this comment.
🟡 Should Fix: Can we keep one copy of the document parser? This block repeats the entire case None parser, although both paths are meant to behave identically. A future fix to tag handling or trailing text would have to be applied twice, and the new test only checks one example.
We can preserve both the type check and the runtime fallback without duplicating the parser:
case None:
pass
case unknown_field:
if TYPE_CHECKING:
assert_never(unknown_field)Then move the existing parsing block below the match. The two forced-field cases already return early, so both parsing paths would reach the same implementation.
There was a problem hiding this comment.
Implemented the suggested refactor in f3d5cbec: the None and unexpected-runtime-value paths now share one document parser below the match. The focused syntax check passed, and the full PR CI matrix has restarted.
|
Thanks for the focused review. I agree the parser should have one implementation. I’m going to move the shared document parsing below the match so both the |
Signed-off-by: Slai.life <huong8373tt@gmail.com>
ad807e6 to
f3d5cbe
Compare
Summary
Noneand preserve the historical fallback for unexpected runtime valuesPart of #3166 (P311-03).
Validation:
Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.