Generate music using ElevenLabs Music API - instrumental tracks, songs with lyrics, and fine-grained composition plans
95
93%
Does it follow best practices?
Impact
99%
1.57xAverage score across 5 eval scenarios
Passed
No findings from the security scan
A creative agency is building an internal web service where designers can type in a description and get AI-generated music for their projects. Since designers may type anything — including references to popular songs or artists for inspiration — the service needs to handle content restriction errors gracefully and guide users toward valid alternatives.
Write a Python module called music_service.py that provides a generate_music(user_prompt, duration_ms) function. This function should:
The agency also wants a companion test file called test_prompts.py that demonstrates the function being called with both a safe prompt and a prompt that would likely be flagged (e.g., one referencing a real band name), showing how the retry logic works.
music_service.py — The Python module with the generate_music functiontest_prompts.py — Demo script showing usage with safe and unsafe prompts