Repository navigation
fix(llm): render missing {} and formatted template placeholders as empty - #7783
Merged
longcw merged 1 commit intoOct 19, 2026
Merged
Conversation
safe_render promises that a placeholder with no value becomes an empty string,
but Instructions.render(data=...) raised instead for three kinds of placeholder:
auto-numbered {} and indexed {0} raised IndexError, which get_field did not catch,
and a format spec such as {price:.2f} raised ValueError because the empty-string
stand-in was formatted with it. Return None for a missing field so format_field
renders it empty without applying the spec, and keep None through convert_field
so {x!s} does not render "None".
Contributor
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
|
I think the PR addressed the problems it found, lgtm in general. Adding @longcw or @theomonnom for a second look to double check if it already covers all the use cases that we need. |
longcw
approved these changes
Oct 19, 2026
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.
Problem:
safe_render's docstring says missing keys become empty strings, andInstructions.render(data=...)repeats that. Three kinds of placeholder raise instead:{}and{0}look up positional args, which are always empty here, soget_fieldraisesIndexError; it only caughtKeyError,AttributeErrorandTypeError. For{price:.2f}the lookup is caught, but the""stand-in is then formatted with.2f.Fix: catch
IndexErrortoo, and returnNonefor a missing field instead of"".format_fieldalready rendersNoneas empty before applying the spec.convert_fieldpassesNonethrough, so{x!s}stays empty instead of becoming"None".Tests
test_render_missing_placeholders_become_emptyintests/test_chat_ctx.py, through the publicInstructions.render. Onmain:The fourth case (
{caller!s}) passes onmainand is there so returningNonecan't leak"None"into a prompt.ruff format,ruff check,make type-checkpass.uv run pytest --unit --audio_eot -q: 5045 passed, 5 skipped.Scope:
safe_renderonly. Placeholders that resolve to a value render as before. One side effect: an explicitNonevalue with!s/!rnow renders empty rather than"None", matching the docstring's "Nonevalues also become empty strings".