Skip to content

fix(prompts): preserve literal values in LangChain prompt conversion - #2060

Open
remote-controlled-man wants to merge 4 commits into
langfuse:mainfrom
remote-controlled-man:codex/prflow-83edbc38646c
Open

remote-controlled-man wants to merge 4 commits into
langfuse:mainfrom
remote-controlled-man:codex/prflow-83edbc38646c

Conversation

@remote-controlled-man

@remote-controlled-man remote-controlled-man commented Oct 26, 2026 •

Copy link
Copy Markdown

What does this PR do?

Precompiled prompt values can contain braces, such as Use {name} or {{question}}. get_langchain_prompt(context=...) currently turns those values into LangChain variables, causing missing-key errors or changing the supplied text during formatting.

Keep supplied braces opaque while converting the template, then escape them for LangChain. Preserve the existing JSON conversion order and evaluate only referenced values. Apply this to text prompts, chat prompts and resolved message history. Unfilled variables still belong to LangChain; ordinary compile() behavior is unchanged.

Type of change

  • Bug fix

Verification

uv sync --locked --python /opt/homebrew/opt/python@3.12/bin/python3.12
.venv/bin/python -m pytest tests/unit/test_prompt_compilation.py -q
.venv/bin/ruff check .
.venv/bin/ruff format --check langfuse/model.py tests/unit/test_prompt_compilation.py
.venv/bin/mypy langfuse --no-error-summary

59 prompt-compilation tests pass, including literal-brace regressions through real LangChain templates. The initial regression run failed 8 cases on unchanged source. Backend e2e and live-provider tests were not run: this conversion is covered locally without a server or model requests.

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added regression tests for the changed behavior.
  • Existing examples and environment settings remain accurate.
  • No generated files were edited.
  • No credentials were committed.

AI disclosure: OpenAI Codex found this during a source audit and prepared the patch, tests and description.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

The PR keeps braces in supplied values literal when converting text and chat prompts for LangChain.

  • Text and chat prompts keep supplied braces literal in LangChain.

No actionable issues were found.

Reviews (1) · Last reviewed commit: "fix(prompts): avoid evaluating unused co..." · Reviewed by Greptile

Copilot AI balanced review requested due to automatic review settings October 26, 2026 08:50

@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.

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@CLAassistant

CLAassistant commented Oct 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

3 participants