litellm/llms/openai/transcriptions/guardrail_translation/README.md
Handler for processing OpenAI's audio transcription endpoint (/v1/audio/transcriptions) with guardrails.
This handler processes audio transcription responses by:
The input is an audio file, which cannot be guardrailed (it's binary data, not text).
{
"model": "whisper-1",
"file": "<audio file>",
"response_format": "json",
"language": "en"
}
{
"text": "This is the transcribed text from the audio file."
}
Or with additional metadata:
{
"text": "This is the transcribed text from the audio file.",
"duration": 3.5,
"language": "en"
}
The handler is automatically discovered and applied when guardrails are used with the audio transcription endpoint.
curl -X POST 'http://localhost:4000/v1/audio/transcriptions' \
-H 'Authorization: Bearer your-api-key' \
-F '[email protected]' \
-F 'model=whisper-1' \
-F 'guardrails=["pii_mask"]'
The guardrail will be applied to the output transcribed text only.
curl -X POST 'http://localhost:4000/v1/audio/transcriptions' \
-H 'Authorization: Bearer your-api-key' \
-F 'file=@meeting_recording.mp3' \
-F 'model=whisper-1' \
-F 'guardrails=["mask_pii"]' \
-F 'response_format=json'
If the audio contains: "My name is John Doe and my email is [email protected]"
The transcription output will be: "My name is [NAME_REDACTED] and my email is [EMAIL_REDACTED]"
curl -X POST 'http://localhost:4000/v1/audio/transcriptions' \
-H 'Authorization: Bearer your-api-key' \
-F '[email protected]' \
-F 'model=whisper-1' \
-F 'guardrails=["content_moderation"]'
text (string)Override these methods to customize behavior:
process_output_response(): Customize how transcribed text is processedprocess_input_messages(): Currently a no-op, but can be overridden if neededCallTypes.transcription - Synchronous audio transcriptionCallTypes.atranscription - Asynchronous audio transcriptionimport litellm
response = litellm.transcription(
model="whisper-1",
file=open("interview.mp3", "rb"),
guardrails=["mask_pii"],
)
# response.text will have PII redacted
print(response.text)
import litellm
import asyncio
async def transcribe_with_guardrails():
response = await litellm.atranscription(
model="whisper-1",
file=open("audio.mp3", "rb"),
guardrails=["content_filter"],
)
return response.text
text = asyncio.run(transcribe_with_guardrails())