AWS Builder Center
Beating the 256 KB Limit in Step Functions LLM Pipelines

Beating the 256 KB Limit in Step Functions LLM Pipelines

How to avoid States.DataLimitExceeded in Amazon Bedrock workflows with the S3 claim check pattern, state pruning with ResultSelector and OutputPath, and ResultWriter on Distributed Map states.

The first time you wire AWS Step Functions to an Amazon Bedrock document or web-scraping pipeline, everything works in dev on 2-page test files. Then a real user uploads a 40-page PDF or your scraper extracts a verbose HTML page, and your state machine crashes mid-flight with a fatal error:
 States.DataLimitExceeded: The state/task returned a result with a size exceeding the maximum number of bytes service limit (262144 bytes). 
Step Functions enforces a hard 256 KB limit on the input and output payload passed between states. When you are chaining RAG retrieval chunks, multi-page transcripts, or base64 screenshots across multiple agents, 256 KB is used up quickly.
Here is how to avoid  States.DataLimitExceeded  with the Amazon S3 claim check pattern and Step Functions Distributed Map.

Why LLM Workflows Hit 256 KB So Quickly

In traditional CRUD microservices, state payloads are tiny JSON objects ( { "orderId": "123", "status": "PAID" } ). In generative AI workflows, payloads bloat across three stages:
Pipeline Stage
Typical Payload Content
Illustrative Size
Hits 256 KB Limit?
1. Document / Web Extraction
Raw markdown + DOM metadata from 3–5 pages
80 KB – 450 KB
Yes (frequently)
2. RAG Context Hydration
Top 10 chunks from Bedrock Knowledge Bases + citations
40 KB – 180 KB
Yes (when combined with state input)
3. Multi-Agent Parallel Map
Array of 25 analyzed sections returned by  Map  state
300 KB – 2 MB
Yes (almost guaranteed)
Sizes are illustrative ranges for planning, not measurements; your payloads depend on page length and chunk settings.
Even if each individual task outputs 90 KB, using  ResultPath: "$.stepOutput"  appends each step's result onto the existing state object, so the cumulative payload can cross 256 KB by step three.

Pattern 1: The Amazon S3 Claim Check Pattern

Lambda writes big payload to S3; Step Functions passes only the pointer

Instead of passing raw text, embeddings, or base64 images through the Step Functions state payload, store the heavy payload in Amazon S3 and pass only a lightweight pointer (the claim check) between states:
{
"executionId": "exec-2026-1109-a8f2",
"tenantId": "tenant-acme",
"claimCheck": {
"bucket": "agent-pipeline-artifacts-prod",
"extractedMarkdownKey": "executions/exec-2026-1109-a8f2/01-extracted.md",
"ragChunksKey": "executions/exec-2026-1109-a8f2/02-rag-chunks.json",
"contentSha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
}

Reusable Claim Check Helper for AWS Lambda

A small wrapper lets any Lambda step offload outputs larger than a safe threshold (for example, 32 KB) to S3 automatically:
// lib/claim-check.ts
import { S3Client, PutObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';

const s3 = new S3Client({ region: process.env.AWS_REGION });
const BUCKET = process.env.ARTIFACT_BUCKET!;

export interface S3Pointer {
__claimCheck: true;
bucket: string;
key: string;
byteLength: number;
}

export async function storeArtifact(
executionId: string,
stepName: string,
data: unknown
): Promise<S3Pointer> {
const serialized = JSON.stringify(data);
const byteLength = Buffer.byteLength(serialized, 'utf8');
const key = `executions/${executionId}/${stepName}.json`;

await s3.send(
new PutObjectCommand({
Bucket: BUCKET,
Key: key,
Body: serialized,
ContentType: 'application/json',
})
);

return {
__claimCheck: true,
bucket: BUCKET,
key,
byteLength,
};
}

export async function resolveArtifact<T>(pointer: S3Pointer): Promise<T> {
const res = await s3.send(
new GetObjectCommand({
Bucket: pointer.bucket,
Key: pointer.key,
})
);
const raw = await res.Body!.transformToString('utf-8');
return JSON.parse(raw) as T;
}
Set an S3 Lifecycle Rule on the  executions/  prefix to expire objects after 7 or 14 days so temporary state blobs never accumulate storage charges.

Pattern 2: Aggressive State Pruning with  ResultSelector  and  OutputPath 

Many state machines accidentally carry AWS SDK metadata ( $metadata , HTTP headers, consumed capacity blocks) across every state transition.
Use  ResultSelector  in your Amazon States Language (ASL) definition to strip everything except the pointer and token counts before merging into state:
{
"GenerateSectionSummary": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"FunctionName": "SummarizeWithBedrock",
"Payload.$": "$"
},
"ResultSelector": {
"summaryPointer.$": "$.Payload.summaryPointer",
"inputTokens.$": "$.Payload.usage.inputTokens",
"outputTokens.$": "$.Payload.usage.outputTokens"
},
"ResultPath": "$.summaryStep",
"Next": "EvaluateQualityGate"
}
}

Pattern 3: Use  ResultWriter  on Map States

If you use an inline  Map  state to fan out 50 document chunks to Amazon Bedrock in parallel, the  Map  state collects an array of all 50 outputs as its final result, which can easily pass 256 KB.
Switching the  Map  state to Distributed Map with a  ResultWriter  configuration instructs Step Functions to write the aggregated results directly to an S3 manifest file instead of returning the full array in memory:
{
"ProcessDocumentChunks": {
"Type": "Map",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "InvokeBedrockChunkWorker",
"States": {
"InvokeBedrockChunkWorker": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"OutputPath": "$.Payload",
"End": true
}
}
},
"ResultWriter": {
"Resource": "arn:aws:states:::s3:putObject",
"Parameters": {
"Bucket": "agent-pipeline-artifacts-prod",
"Prefix": "map-outputs"
}
},
"Next": "ReduceSummariesFromS3"
}
}

Key Takeaways

  1. Keep state payloads small: Treat Step Functions state as a control-plane envelope for IDs, status flags, and S3 URIs, never as a document transport bus.
  1. Strip SDK Metadata Early: Always apply  ResultSelector  on  lambda:invoke  and  bedrock:invokeModel  tasks so SDK wrappers don't snowball across steps.
  1. Export Map Results via  ResultWriter : Whenever a parallel fan-out processes more than a handful of items, let Step Functions write the manifest directly to S3.
Have you run into  States.DataLimitExceeded  in your Step Functions workflows? How do you structure your S3 claim-check keys and lifecycle policies? Drop your approach in the comments!
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article