Model-specific input formatting and enrichment

Lesson 3 of 3 in Data Pipelines for FM Consumption.

A request that is perfect for one model is malformed for another, because AWS offers three different request contracts: InvokeModel with a model-specific JSON body (each provider defines its own fields), the Converse API with one uniform shape across models (messages, system, inferenceConfig, toolConfig — the provider-switch enabler), and SageMaker AI endpoints, where your inference container defines the contract (JSON lines, CSV, whatever you deployed). Dialog applications add conversation formatting: alternating user/assistant turns with the system prompt carried separately — because models are stateless, the full formatted history rides along on every call.

InvokeModel (native)

The raw door: the request body is the provider's own schema — field names, parameter spellings, and content structure differ per model family, and sending one family's body to another fails.

{
  "anthropic_version": "bedrock-2023-05-31",
  "max_tokens": 512,
  "messages": [{ "role": "user", "content": "…" }]
}

Reach for it when you need a model-specific capability the uniform API has not surfaced — and accept that your marshalling code is now coupled to the provider.

Converse (uniform)

One shape for every supported model:

{
  "modelId": "us.anthropic.claude-sonnet-…",
  "system": [{ "text": "You are a support analyst." }],
  "messages": [{ "role": "user", "content": [{ "text": "…" }] }],
  "inferenceConfig": { "maxTokens": 512, "temperature": 0.2 }
}

Swap modelId (or an inference profile ID) and nothing else changes — which is why every provider-switch architecture in this domain assumes Converse.

SageMaker endpoints

For models you host — fine-tuned deployments included — the contract is whatever your inference container accepts: structured JSON, JSON lines, CSV. "Structured data preparation for SageMaker AI endpoints" (the phrase in the AIP-C01 exam guide) means shaping records to that container contract and validating them against it before invoking, exactly like any API integration.

Which request contract?

Interactive decision tree — outcomes:

  • Converse API

    The uniform shape: messages, system, inferenceConfig, toolConfig, multimodal content blocks. Model identity becomes configuration; marshalling code survives every switch.

  • InvokeModel with the native body

    Full access to the provider's schema at the price of coupling. Isolate it behind your adapter layer so the coupling has one address.

  • Your container's contract

    The endpoint accepts what your inference container was built to parse — document it, validate inputs against it, and version it with the model.

Enrichment: Bedrock reformatting text

The first move: use an FM itself as a preprocessing tool — normalize messy free text, summarize sprawl, convert formats — before the data is indexed or sent to the main model. Cheap models make good janitors for expensive ones.

Enrichment: Comprehend entity extraction

Amazon Comprehend extracts entities (people, orgs, products), key phrases, sentiment, and PII at ingest. Stored as metadata beside each chunk, those entities later power filtered retrieval ("only documents mentioning product X") and routing — enrichment at write time buys precision at read time.

Enrichment: Lambda normalization

The unglamorous third: canonical date formats, unit conversions, locale normalization, ID canonicalization. Consistent inputs raise response consistency, because the model stops burning attention reconciling five spellings of the same fact.

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.