Skip to main content

Extraction state machine

Extracts structured data from bank statement PDFs using Bedrock Data Automation (BDA). Invokes BDA asynchronously against a custom bank statement blueprint, polls until complete, then emits a DocumentProcessing-Extracted event for downstream processing.

Flow​

States​

StateTypePurpose
CheckIsBankStatementChoiceGuard: only BANK_STATEMENT and TRANSACTION_REPORT proceed
InvokeBedrockDataAutomationTaskAsync BDA invocation — returns InvocationArn immediately
WaitForBedrockWait10-second pause before polling
GetBedrockStatusTaskPoll GetDataAutomationStatus using the InvocationArn
CheckBedrockStatusChoiceRoute on Status: Success / Failed / ClientError / still-in-progress
PrepareExtractedDataPassFlatten state — promotes BDA invocation metadata to top level
EmitExtractedEventTaskEventBridge PutEvents — DocumentProcessing-Extracted
EmitSkippedEventTaskEventBridge PutEvents — DocumentProcessing-ExtractionSkipped
EmitExtractionFailedEventTaskEventBridge PutEvents — DocumentProcessing-ExtractionFailed

Why CheckIsBankStatement exists​

The EventBridge routing rule already filters on classification before starting this SM, so under normal operation CheckIsBankStatement is always satisfied. The state is a defensive guard — if the SM is triggered manually or routing policy changes, documents that aren't bank statements skip directly to EmitSkippedEvent rather than wasting a BDA invocation.

BDA configuration​

The BDA project and blueprint are managed in modules/idp/bda.tf (Terraform, via the awscc provider):

SettingValueReason
SplitterENABLEDSegments bundled/mixed PDFs; only segments matching the blueprint get custom_output. Raises async page limit from 20 to 3000.
Document granularityDOCUMENTNo per-page or per-word noise in the output JSON
Bounding boxDISABLEDPosition metadata not needed by downstream Claude analysis
Text formatMARKDOWNPlain text / HTML / CSV duplicates disabled
Additional file formatDISABLEDJSON only — no JSON+ side files
Generative fieldDISABLEDNo BDA-generated descriptions or summaries
Image / video / audioDISABLEDPDFs only — prevents BDA running unnecessary modalities

Custom blueprint​

modules/idp/config/bank-statement-blueprint.json defines the structured extraction schema. Key design decisions:

  • Signed balances and amounts — negative values represent debits/overdrafts. Overdraft state flows through as data (e.g. -250.00) rather than being reconstructed by the downstream Claude analysis prompt from DR/OD markers.
  • Running balance per transaction — enables Claude to verify balance continuity without re-summing all transactions.
  • Arranged overdraft limit — extracted explicitly to support operator licensing financial standing checks.

Config injection​

All BDA config (outputBucket, bedrockProjectArn, bedrockProfileArn, bedrockProjectStage) is injected into the SM input via the Classification SM's EventBridge input transformer in modules/idp/main.tf. The extraction ASL consumes it via $.config.* — no hardcoded ARNs in the ASL.

Emitted events​

Success — DocumentProcessing-Extracted​

{
"Source": "custom.documentProcessing",
"DetailType": "DocumentProcessing-Extracted",
"Detail": {
"bucket": "...",
"key": "...",
"object": { "size": 7390634, "versionId": "..." },
"config": { "outputBucket": "vol-idp-dev-output", "..." : "..." },
"classification": "BANK_STATEMENT",
"classificationConfidence": 0.75,
"totalPages": 47,
"classifiedPages": 20,
"dominantTypePages": 15,
"pageBreakdown": [...],
"documentSizeBytes": 7390634,
"modelId": "eu.anthropic.claude-haiku-4-5-20251001-v1:0",
"bedrockInvocationArn": "arn:aws:bedrock:eu-west-1:...:async-invoke/...",
"bedrockInvocationId": "...",
"extractedDataS3Bucket": "vol-idp-dev-output",
"extractedDataS3KeyPrefix": "migration/olcs/.../document.pdf/brda/"
}
}

Skip — DocumentProcessing-ExtractionSkipped​

Emitted when the document classification is not a bank statement type. Includes bucket, key, object, config, classification, and reason.

Failure — DocumentProcessing-ExtractionFailed​

Emitted on BDA Failed/ClientError status or SDK errors. Includes bucket, key, object, config, reason, error, cause, and the full bedrockStatus object.

Timing​

StepTypical
CheckIsBankStatement<1 s
InvokeBedrockDataAutomation1–3 s
BDA processing (polling loop, varies by size)30 s–10 m
PrepareExtractedData + EmitExtractedEvent<1 s
Total~1–10 min

SM timeout is 30 minutes to cover large or complex documents.