AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Pretty_repr() Exposes Partial Variable Values Instead Of Showing Template Placeholders

When a prompt template contains partial variables, pretty_repr() formats the template with dummy variables only for input_variables, causing the real partial values to be substituted and exposed in the output. This breaks the expectation that pretty_repr() shows the original template structure.

mediumConfidence 85%LangchainAffected V1.4.4

Origin Analysis

The pretty_repr() implementation builds dummy variables as `{var}` for each entry in `input_variables` to preserve placeholders during formatting, but it does not include keys from `partial_variables`. As a result, `prompt.format(**dummy_vars)` merges the actual partial values into the template, exposing them.
```python from langchain_core.prompts import PromptTemplate p = PromptTemplate.from_template("Hello {user}, how is {input}?").partial(user="Lucy") print(p.pretty_repr()) ``` Observed output contains `Hello Lucy, how is {input}?` instead of the expected `Hello {user}, how is {input}?`.

Fixing Code Block

def _get_string_prompt_repr(prompt: StringPromptTemplate, html: bool = False) -> str: """Get a pretty representation of a string prompt template.""" dummy_vars = {var: f"{{{var}}}" for var in prompt.input_variables} # Include partial variables as placeholders to avoid exposing real values dummy_vars.update({var: f"{{{var}}}" for var in prompt.partial_variables}) template = prompt.format(**dummy_vars) return _dict_repr( { "input_variables": prompt.input_variables, "partial_variables": prompt.partial_variables, "template": template, }, html=html, )
By adding partial variable names to the dummy variables with placeholder values like `{var}`, the format() call no longer sees them as missing and does not substitute the actual partial values. The placeholder values override the real partials because user-provided kwargs take precedence over partial_variables in `_merge_partial_and_user_variables`. This preserves the original template structure in the pretty representation. The same approach should be applied to message prompt representations that use similar dummy variable logic.

Edge Case Audit

If a custom partial implementation leaves a variable in both input_variables and partial_variables, the placeholder will override the real value, which is consistent with the intended placeholder display but may surprise users who expect the partial value to be shown. The change assumes that passing extra kwargs not present in input_variables is harmless; custom template formats that reject unknown variables could raise. Rollback: remove the `dummy_vars.update(...)` line to restore previous behavior.

Ecosystem Topology