Skip to content

Commit 173cfa8

Browse files
committed
Add type validation to prompt_with_handoff_instructions
Ensure that the prompt parameter is validated as a string at runtime, preventing unexpected behavior when non-string types are passed. The function now raises a TypeError with a descriptive message when invalid types are provided.
1 parent 9407743 commit 173cfa8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/agents/extensions/handoff_prompt.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@
1515
def prompt_with_handoff_instructions(prompt: str) -> str:
1616
"""
1717
Add recommended instructions to the prompt for agents that use handoffs.
18+
19+
Args:
20+
prompt: A string containing the prompt to which handoff instructions will be added
21+
22+
Returns:
23+
A string with the recommended handoff instructions prepended to the provided prompt
24+
25+
Raises:
26+
TypeError: If the prompt is not a string
1827
"""
28+
if not isinstance(prompt, str):
29+
raise TypeError(f"prompt must be a string, got {type(prompt).__name__}")
30+
1931
return f"{RECOMMENDED_PROMPT_PREFIX}\n\n{prompt}"

0 commit comments

Comments
 (0)