Use a replayable, provider-neutral pipeline for long-document text to JSON extraction when a timeout threatens the result: bound every model request, keep evidence beside each field, and make CRM writes idempotent. The choice that matters is portability. A transcript should survive a model swap, a gateway change, or a failed retry without changing the resulting opportunity record.

I build small CLIs and SDKs for other developers, so I care about time-to-first-call and the amount of glue left behind. Long calls expose bad abstractions fast. A 90-minute media sales call can contain pricing, rights windows, territories, delivery dates, and a dozen tentative statements. Sending the entire transcript to one request looks tidy until the request times out or the context limit clips the last commitment. Then someone adds a bigger timeout and calls the problem solved.

That is a trap. A timeout is an interface boundary, not a capacity plan.

What should the pipeline guarantee before it writes to a CRM?

The output contract needs four fields for every proposed action: a normalized value, a source span, a confidence band, and a review state. The source span is the important one. It lets a sales operations editor inspect “exclusive streaming rights, Q3” without rereading the whole call.

I use three stages:

  1. Locate. Split the transcript into bounded chunks, preserving speaker and timestamp metadata. Retrieve chunks using lexical matching plus embeddings when a phrase can be paraphrased.
  2. Extract. Ask for a small JSON object from each selected chunk. The schema is fixed and versioned. Unknown values stay null; the model does not invent them.
  3. Reconcile. Merge claims, resolve conflicts, and produce a dry-run CRM patch. A human or a deterministic rule approves the patch before the write.

The stages are deliberately boring. Boring stages are easy to replay. If a provider changes its tokenization, I can rerun extraction from stored chunks instead of paying to transcribe and classify the call again.

How should text-to-JSON extraction handle a long document timeout?

Token limits and wall-clock limits are coupled, but they are different controls. Input tokens determine whether a request is accepted. Output tokens and queue time determine whether it finishes before the caller gives up. A long transcript can fit under an advertised context window and still exceed a practical deadline after retrieval, generation, and network time are added.

The retry still costs latency. That is a real trade-off, not a defect to hide.

Set a budget per stage. For example, a locator can have 800 ms, each extraction call 8 seconds, and reconciliation 10 seconds. Those numbers are policy defaults, not universal truths; measure them with your own transcript mix. Keep the client deadline shorter than the job lease so a worker has time to record the failure and release the lease.

Chunk by meaning first, then by tokens. A speaker turn is a useful boundary, but a single turn can be enormous when a producer reads a contract aloud. In that case, cut on sentence boundaries with a small overlap. Store chunk_id, start and end timestamps, and a hash of the text. The hash makes retries and deduplication cheap.

Here is the smallest TypeScript shape I use for a provider adapter. It says nothing about a vendor SDK. That is the point.

type ExtractRequest = { model: string; input: string; schemaVersion: string; deadlineMs: number; }; type ExtractResult = { json: unknown; usage?: { inputTokens: number; outputTokens: number }; requestId?: string; }; interface TextExtractor { extract(request: ExtractRequest): Promise<ExtractResult>; } async function boundedExtract( extractor: TextExtractor, request: ExtractRequest, ): Promise<ExtractResult> { const timer = new AbortController(); const timeout = setTimeout(() => timer.abort(), request.deadlineMs); try { return await extractor.extract(request); } finally { clearTimeout(timeout); } } 

The adapter should translate cancellation, rate limits, malformed JSON, and upstream 5xx responses into a small internal error set. Callers then decide whether to retry, defer, or send the chunk to review. They do not parse provider-specific strings.

Why is chunking alone a weak fix?

Naive chunking loses relationships. “We can license the archive in Europe” may be in one chunk, while “only if the sports package is renewed” is in the next. Retrieval should pull both when the target field is a rights constraint. Embeddings help with paraphrases; lexical search catches exact contract terms such as territory codes and dates. A reranker can order the candidates, but it should not be the source of truth. Keep the original rank signals and the selected evidence IDs in the trace.

For a media call, I would retrieve at most 6–8 chunks for a field group, then cap the extraction input by tokens. If the cap is hit, emit a partial result with review_state: "needs_more_context". Silently dropping the tail creates a confident-looking omission, which is harder to detect than an explicit gap.

The merge step needs deterministic rules. Prefer an explicit date over “soon.” Prefer a statement marked confirmed over a question. If two confirmed values conflict, keep both with their timestamps and stop the automatic CRM write. This is where a little human review beats another model call.

What does a portable retry contract look like?

Retries are safe only when the operation is safe to repeat. HTTP semantics distinguish idempotent methods and require clients to consider the possibility that a request was processed before a connection failed. The same discipline belongs in the extraction worker.

Give every job a stable key such as call_id + schema_version + chunk_hash. Persist the attempt, response hash, and evidence IDs before acknowledging the queue message. A retry with the same key can return the stored result. The CRM patch then uses its own idempotency key, so a worker crash cannot create duplicate activities.

I also keep a dead-letter record with the exact chunk, policy version, and error class. That record is more useful than a generic “timeout” metric because it can be replayed after a model or gateway change.

What I would change at scale

At a few calls per hour, one worker and a durable table are enough. At hundreds of calls, separate transcription, retrieval, extraction, and CRM publication queues. Give each queue a lease and a bounded concurrency setting. Measure p50 and p95 latency by stage, token counts by field group, evidence coverage, and the percentage of patches sent to review.

Provider portability has a cost. Different systems expose different token counters, structured-output guarantees, and cancellation behavior. Hide those differences behind the adapter, but keep a capability matrix in configuration. A model that cannot enforce your JSON schema should be routed to a parser-and-validator path, not treated as equivalent. This approach is a poor fit for teams that need sub-second synchronous updates or cannot retain transcript evidence; a smaller, single-pass classifier may be the better boundary there.

I would spend the next week on replay fixtures before tuning prompts. Keep ten representative calls, including one with a rights dispute and one with a very long monologue. Run the same fixture through every adapter, compare normalized JSON and evidence spans, and fail the build when a field disappears without a review flag. That catches portability regressions earlier than a dashboard does.

The practical rule is simple: extract small claims, carry their evidence, and make every side effect replayable. Timeouts then become visible queue events instead of mysterious missing CRM actions. The pipeline can change providers without changing what a salesperson sees.

References