Skip to content

fix(model): use each non-dict placeholder item instead of the whole list - #2071

Open
AsherLucas wants to merge 1 commit into
langfuse:mainfrom
AsherLucas:fix-placeholder-non-dict-item
Open

AsherLucas wants to merge 1 commit into
langfuse:mainfrom
AsherLucas:fix-placeholder-non-dict-item

Conversation

@AsherLucas

@AsherLucas AsherLucas commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #1971.

Problem

In ChatPromptClient.compile, when a placeholder value is a list and an item is not a dict, the code appended str(placeholder_value) — the whole list — for every such item. So compile(history=["a", "b"]) produced two identical messages containing "['a', 'b']", instead of one message per item.

Change

  • langfuse/model.py: in the per-item else branch, use str(msg) for the current item. The non-list placeholder path is unchanged, so a placeholder that is not a list still appends the whole value once.
  • tests/unit/test_prompt.py: updated the existing parametrized case that encoded the old behaviour — it now expects "invalid message" for the non-dict item.
  • tests/unit/test_prompt_compilation.py: added test_compile_non_dict_placeholder_items_use_each_item as a regression test for bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder item #1971.

Verification

  • New test failed before the fix (asserted "['a', 'b']" == "a") and passes after it.
  • pytest tests/unit/test_prompt.py tests/unit/test_prompt_compilation.py: 41 passed, 18 errors.
  • The 18 errors are pre-existing and unrelated: they are fixture setup errors in test_prompt.py when no LANGFUSE_* env vars are set (see tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env vars #1976). I confirmed the same 18 errors on the clean tree before my change, with no failures there.
  • ruff format --check passed for the changed files. A local ruff check reported 40 errors in langfuse/model.py, but the same 40 appear on the clean tree with the ruff version available here, none on the changed lines, so I did not touch them.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

Fixes ChatPromptClient.compile so each non-dictionary placeholder item becomes its own string instead of repeating the whole list.

  • Chat placeholders keep each non-dictionary list item’s text.

Reviews (1) · Last reviewed commit: "fix(model): use each non-dict placeholde..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Oct 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@AsherLucas AsherLucas changed the title fix(model): use each non-dict placeholder item instead of the whole list fix(model): use each non-dict placeholder item instead of the whole list Oct 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder item

2 participants