#16089: fix(tts): clarify directive syntax in prompts and strip malformed tags
channel: whatsapp-web
agents
stale
size: S
Cluster:
Voice Call and TTS Improvements
## Summary
The system prompt hint for TTS directives was vague (`[[tts:...]]`), leading models to invent unsupported syntax like `[[tts:soft]]` or emit orphan `[[/tts:text]]` closing tags that get read aloud verbatim.
This PR:
- Replaces the vague hint with explicit key=value examples and available parameter names (stability, style, speed, similarityBoost)
- Warns when models use bare directives without key=value format
- Strips orphan `[[/tts:*]]` closing tags that leak through to the TTS engine
- Parses directives in the TTS tool path so tags in tool call text are cleaned before synthesis
## Test plan
- [x] Added tests for orphan closing tag stripping (end-of-text and mid-text)
- [x] Added assertion that paired block tags do not leak closing tags
- [x] All 37 TTS tests pass
- [x] Tested live via WhatsApp
Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Improved TTS directive parsing to prevent malformed tags from being read aloud. Replaced vague system prompt hint with explicit key-value syntax examples, added orphan closing tag stripping, and warns models when using unsupported bare directives.
- Updated system prompt to show explicit parameters (like `stability`, `style`, `speed`, `similarityBoost`) with examples
- Strips orphan closing tags that models sometimes emit without matching openers
- Warns when models use bare directives instead of required key-value format
- Integrated directive parsing in tts-tool so tags in tool call text are cleaned before synthesis
- Tests cover orphan tag stripping at end-of-text and mid-text positions
<h3>Confidence Score: 5/5</h3>
- Safe to merge - focused fix with comprehensive test coverage
- The changes are well-contained, defensive (adding fallback stripping), and thoroughly tested with 37 passing tests. The implementation correctly handles edge cases like orphan tags and bare directives, improving UX without breaking existing functionality.
- No files require special attention
<sub>Last reviewed commit: cb2ca7e</sub>
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#8317: fix(tts): add dynamic timeout and retry logic for ElevenLabs TTS
by camtang26 · 2026-02-03
79.4%
#22086: fix(tts): honor explicit config provider and model/voice settings
by AIflow-Labs · 2026-02-20
79.1%
#20992: fix(tts): apply TTS processing to agentCommand outbound delivery path
by mmyyfirstb · 2026-02-19
79.1%
#21110: fix(tts): deliver audio via structured mediaUrl instead of MEDIA: t...
by hydro13 · 2026-02-19
78.7%
#19210: feat(tts): add OpenAI instructions parameter support
by keenranger · 2026-02-17
77.9%
#8103: fix(tts): sanitize API keys from error messages
by yubrew · 2026-02-03
77.6%
#17244: fix: strip TTS tags from agent replies before delivery (#14652)
by robbyczgw-cla · 2026-02-15
76.9%
#18957: fix(tts): replace deprecated ElevenLabs eleven_monolingual_v1 model
by BinHPdev · 2026-02-17
76.5%
#7965: feat(tts): add Speechify as TTS provider
by chaerla · 2026-02-03
76.4%
#19073: feat(voice-call): streaming TTS, barge-in, silence filler, hangup, ...
by odrobnik · 2026-02-17
76.3%