Skip to content

Commit c61c9d0

Browse files
Validate prompt_template type for clearer user-facing errors
1 parent 89ae8f0 commit c61c9d0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

python/mllmcelltype/prompts.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ def create_prompt(
129129
"""
130130
write_log(f"Creating prompt for {len(marker_genes)} clusters")
131131

132+
# Validate custom template type and use default template when empty.
133+
if prompt_template is not None and not isinstance(prompt_template, str):
134+
raise ValueError(
135+
f"prompt_template must be a string or None, got {type(prompt_template).__name__}"
136+
)
137+
132138
# Use default template if not provided
133-
if not prompt_template:
139+
if not prompt_template or not prompt_template.strip():
134140
prompt_template = DEFAULT_PROMPT_TEMPLATE
135141

136142
# Default tissue if none provided

python/tests/test_prompts.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ def test_create_prompt_with_malformed_template_raises_clear_error(self):
8888
prompt_template=bad_template,
8989
)
9090

91+
def test_create_prompt_with_non_string_template_raises_clear_error(self):
92+
"""Test non-string custom templates fail with explicit type guidance."""
93+
with pytest.raises(ValueError, match="prompt_template must be a string or None"):
94+
create_prompt(
95+
marker_genes=self.marker_genes,
96+
species="human",
97+
tissue="blood",
98+
prompt_template=123, # type: ignore[arg-type]
99+
)
100+
91101
def test_create_initial_discussion_prompt(self):
92102
"""Test initial discussion prompt creation."""
93103
cluster_id = "1"

0 commit comments

Comments
 (0)