Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Jun 26, 2025

Important

Enhance get_langchain_prompt to escape JSON-related curly braces and add comprehensive tests for JSON handling in prompts.

  • Behavior:
    • Modify BasePromptClient._get_langchain_prompt_string to escape JSON-related curly braces using _escape_json_for_langchain.
    • Handle JSON-related curly braces by doubling them if they are part of a JSON object.
  • Tests:
    • Add extensive tests in test_prompt_compilation.py for JSON handling in prompts.
    • Test scenarios include nested JSON, mixed variable types, empty JSON objects, nested quotes, and real-world complex scenarios.
    • Ensure correct handling of JSON-related braces and variable replacements in TestLangchainPromptCompilation.

This description was created by Ellipsis for 3b96faa. You can customize this summary. It will automatically update as commits are pushed.

Greptile Summary

Disclaimer: Experimental PR review

Fixes critical JSON handling in Langchain prompt integration by implementing proper JSON escaping while preserving template variables. This prevents JSON structures from breaking Langchain template parsing.

  • Added _escape_json_for_langchain method in langfuse/model.py using stack-based parsing for JSON context tracking
  • Implemented comprehensive test suite in tests/test_prompt_compilation.py covering nested JSON, mixed variables, and complex real-world scenarios
  • Ensures backward compatibility with existing prompt templates while fixing JSON structure integrity
  • Handles both text and chat prompt formats with proper JSON escaping

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 3 comments
Edit PR Review Bot Settings | Greptile

@hassiebp hassiebp merged commit d6bef40 into main Jun 26, 2025
10 checks passed
@hassiebp hassiebp deleted the hassieb/lfe-5472-fix-json-in-langchain-prompts branch June 26, 2025 11:47
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.

2 participants