Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion langfuse/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def _compile_template_string(content: str, **kwargs) -> str:

# Append the variable value
if variable_name in kwargs:
result_list.append(str(kwargs[variable_name]))
result_list.append(
str(kwargs[variable_name])
if kwargs[variable_name] is not None
else ""
)
else:
result_list.append(content[var_start : var_end + len(closing)])

Expand Down
7 changes: 7 additions & 0 deletions tests/test_prompt_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def test_missing_variable():
assert BasePromptClient._compile_template_string(template) == expected


def test_none_variable():
template = "Hello, {{name}}!"
expected = "Hello, !"

assert BasePromptClient._compile_template_string(template, name=None) == expected


def test_strip_whitespace():
template = "Hello, {{ name }}!"
expected = "Hello, John!"
Expand Down