LLM API Text Cleanup for Transcripts
An llm api text cleanup job takes raw speech-to-text output and fixes punctuation, casing, filler words and obvious mishearings, without changing what the speaker said. This article gives a prompt, a chunking routine and a safety check you can run on real transcripts.

On this page
- What cleanup should and should not do
- A system prompt that keeps the model in its lane
- Split long transcripts at speaker turns
- Run the chunks in parallel, within the limits
- Stream when a person is watching
- Check that the model did not drift
- What an hour of audio costs to clean
- Other things worth cleaning in the same pass
- More guides
Key points
- Treat cleanup as editing, not rewriting: the prompt must forbid summarizing and adding content.
- Split long transcripts at speaker turns and clean the chunks in parallel, up to 8 at once.
- Compare word counts before and after to catch chunks where the model drifted.
- Ten thousand words of transcript cost under one cent at $0.15 and $0.50 per 1M tokens.
What cleanup should and should not do
Speech-to-text tools such as Whisper give you words, but the words arrive with problems: no paragraph breaks, missing commas, "um" and "you know" scattered through every sentence, product names spelled the way they sound. A language model is good at fixing exactly this, because every correction is a local decision based on the surrounding words.
The risk is the opposite problem. Given a messy transcript and a vague instruction like "improve this", a model may condense, paraphrase or smooth away the speaker's actual wording. For interviews, meeting minutes, legal notes and fiction drafts that is damage, not help. So define the job narrowly:
- Do: add punctuation and capitalization, split into paragraphs, remove filler and false starts, fix clear mishearings using a glossary you supply.
- Do not: summarize, reorder, add facts, soften language, translate, or merge speakers.
Everything below follows from that split. The prompt states it, the chunking keeps the model's attention small, and the final check measures whether the output stayed faithful.
A system prompt that keeps the model in its lane
Put the rules in the system message and keep the transcript alone in the user message. The model sees a clear boundary between instructions and data, which also helps when the transcript itself contains something that sounds like a command.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.whisperapi.cc/v1",
api_key=os.environ["WHISPER_API_KEY"],
max_retries=5,
)
RULES = """You are a transcript editor. The user message is a raw transcript.
Return the same transcript, cleaned. Rules:
1. Keep every speaker label exactly as written, on its own line.
2. Add punctuation, capitalization and paragraph breaks.
3. Remove filler words (um, uh, you know) and repeated false starts.
4. Fix a word only when it is clearly misheard; use the glossary below.
5. Never summarize, shorten, reorder, translate or add information.
6. Keep the speaker's wording and tone, including strong language.
7. Output the cleaned transcript only, with no comments.
Glossary: Kubernetes, PostgreSQL, Grafana, Okafor (surname)"""
def clean_chunk(chunk: str) -> str:
resp = client.chat.completions.create(
model="uncensored",
temperature=0.1,
messages=[
{"role": "system", "content": RULES},
{"role": "user", "content": chunk},
],
)
return resp.choices[0].message.content.strip()Rule 6 is there on purpose. Many chat models quietly tone down rough language when asked to edit it, which changes the record. This service runs one open-weight model tuned to answer without content refusals for lawful adult use, so interview recordings, comedy sets or fiction with strong language go through unaltered, and the model's refusals do not leave holes in your text. The hard limit is the one you would expect: no sexual content involving minors.
Keep temperature low. At 0.1 the model makes the same fix the same way across chunks, which matters when a 90-minute recording is cleaned in nine separate calls. The glossary line is the cheapest accuracy gain available: add the names, products and jargon from the recording, and the model will use them as the target spelling.
Split long transcripts at speaker turns
The context window is 100,000 tokens for prompt and completion together, which is far more than a typical transcript needs. A one-hour talk is about 9,000 to 10,000 words. You could send it all in one request, but you should not, for three reasons. Output length is the limiting factor, because the model must write back as many words as it received. One failed call would lose the whole job. And a single long generation gives you no parallelism.
Chunks of around 2,500 to 3,000 words work well. The one rule is to cut between speaker turns, never in the middle of a sentence. This function walks the transcript line by line and starts a new chunk when the word budget is reached.
def split_turns(text: str, max_words: int = 2800) -> list[str]:
chunks, current, count = [], [], 0
for line in text.splitlines():
words = len(line.split())
if current and count + words > max_words:
chunks.append("\n".join(current))
current, count = [], 0
current.append(line)
count += words
if current:
chunks.append("\n".join(current))
return chunksIf your transcript has no speaker labels and is one long line, split on sentence endings instead, or add a timestamp-based break from the ASR output. A single line longer than the budget will land in a chunk by itself, which is fine.
Context across chunks is the one thing you lose. Terms defined early in the talk can be spelled differently in later chunks. The glossary solves most of that. For a stronger fix, send the last two cleaned lines of the previous chunk inside the user message under a heading such as "CONTEXT ONLY, DO NOT OUTPUT", and add a rule to the system prompt that says so.
Run the chunks in parallel, within the limits
Cleaning nine chunks one after another is slow for no reason. A full key allows 8 concurrent requests and 300 requests per minute, so a small thread pool brings the wall-clock time close to that of a single chunk. A trial key allows 2 concurrent requests and 60 per minute, so set the worker count to match your key.
from concurrent.futures import ThreadPoolExecutor
def clean_transcript(raw: str, workers: int = 8) -> str:
chunks = split_turns(raw)
with ThreadPoolExecutor(max_workers=workers) as pool:
cleaned = list(pool.map(clean_chunk, chunks))
return "\n\n".join(cleaned)
with open("interview.txt", encoding="utf-8") as f:
raw = f.read()
result = clean_transcript(raw, workers=8)
with open("interview.clean.txt", "w", encoding="utf-8") as f:
f.write(result)pool.map returns results in input order, so the chunks come back in the right sequence even when they finish at different times. If you exceed a limit, the API answers HTTP 429 with the error code rate_limited (too many requests per minute) or concurrency (too many at once). On temporary overload it also sends Retry-After: 5. The SDK's built-in retries, set here with max_retries=5, handle both for a batch like this. Details on every parameter are in the quickstart.
Stream when a person is watching
Batch jobs do not need streaming. A review tool where an editor pastes a transcript and watches the cleaned text appear does. Set stream=True and the server sends tokens over SSE as they are generated, with usage reported at the end.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.whisperapi.cc/v1",
api_key=os.environ["WHISPER_API_KEY"],
)
def stream_clean(chunk: str, rules: str) -> str:
out = []
stream = client.chat.completions.create(
model="uncensored",
temperature=0.1,
stream=True,
messages=[
{"role": "system", "content": rules},
{"role": "user", "content": chunk},
],
)
for part in stream:
if part.choices and part.choices[0].delta.content:
piece = part.choices[0].delta.content
out.append(piece)
print(piece, end="", flush=True)
return "".join(out)One thing to remember: a streamed request holds its concurrency slot until the stream finishes. If your interface reads slowly, or a user walks away from an open stream, that slot stays occupied and the other workers wait. Close the stream when the client disconnects.
Check that the model did not drift
Trusting the output blindly is how a summary sneaks into a transcript. The cheapest guard is a length check. Cleaned text should be a bit shorter than the original, because fillers are gone, but not much shorter. Compare word counts per chunk and flag anything outside a band.
def drift_report(raw_chunks: list[str], clean_chunks: list[str]) -> list[tuple[int, float]]:
flagged = []
for i, (a, b) in enumerate(zip(raw_chunks, clean_chunks)):
ratio = len(b.split()) / max(len(a.split()), 1)
if ratio < 0.85 or ratio > 1.05:
flagged.append((i, round(ratio, 2)))
return flaggedA ratio under 0.85 usually means the model condensed. A ratio over 1.05 means it added words, often an introduction such as "Here is the cleaned transcript". For flagged chunks, rerun with temperature 0 or strengthen rule 5 in the prompt. You can also check that every speaker label in the input appears the same number of times in the output, which takes three lines of Python with str.count.
Spot-check by reading two or three random chunks side by side. Automatic checks catch the gross failures. Only a human catches a mishearing that the model confidently turned into a different real word.
What an hour of audio costs to clean
Assume 10,000 words, which is a little over an hour of speech. English text runs at roughly 1.3 tokens per word, a rough rule that varies with vocabulary, so call it 13,000 tokens. With four chunks and a 250-token system prompt on each call, input is 13,000 + 1,000 = 14,000 tokens. Output is about the same length as the transcript, minus the fillers, so call it 13,000 tokens.
Input: 14,000 x $0.15 / 1,000,000 = $0.0021. Output: 13,000 x $0.50 / 1,000,000 = $0.0065. Total: $0.0086, under one cent. A hundred such recordings cost $0.86.
The transcription itself is a separate step. This service handles text only, with no audio input, so run your recordings through the speech-to-text tool of your choice first and send the resulting text here. Prompts are not used for training, which is worth knowing if your recordings are confidential. See the pricing page for top-ups, or the API key page to claim the $0.50 trial credit, which covers dozens of transcripts like the one above.
Other things worth cleaning in the same pass
Once the basic loop works, the same pattern handles neighbouring jobs. Subtitle files need line breaks at natural pauses and a maximum line length. Chat exports need usernames and timestamps left alone. OCR output from scanned pages needs hyphenated line endings joined back into words. Each of these is a different system prompt on the same code.
Keep one prompt per job and name it in your code, so a change to the transcript rules never alters the subtitle rules. When a prompt works, save it with a short test file, a few hundred words with known problems, and run that file again whenever you edit the prompt. If the cleaned result changes in ways you did not intend, the edit caused it.
For structured output, such as a list of speakers with their cleaned lines, switch on JSON mode with response_format={"type": "json_object"} and describe the shape in the prompt. That is also the right format when a later step, such as search indexing, needs the text split by speaker.
More guides
Questions and answers
Can an LLM replace a transcript editor?
It can do the first pass on punctuation, filler words and obvious mishearings. A person should still review anything that will be published or used as a record.
How long can a transcript be in one request?
The context window is 100,000 tokens, shared by prompt and completion. In practice, chunks of about 2,800 words are easier to retry and run in parallel.
Will the model change strong language in my transcript?
The model is tuned to answer without content refusals for lawful adult use, and a prompt rule that says to keep wording makes it preserve the original. Check a sample, as with any model.
Does the API accept audio files?
No. It is text only. Transcribe the audio elsewhere, then send the text for cleanup.
How do I speed up a big batch?
Clean chunks in parallel, up to 8 concurrent requests on a full key and 2 on a trial key. Stay under 300 requests per minute on a full key.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.