Skip to main content
This article walks through preparing JSON Lines (JSONL) training data, launching a fine-tuning (customization) job with Amazon Bedrock, and invoking hosted models for inference. It includes practical boto3 examples, recommended hyperparameters, hosting options, and expected outcomes from fine-tuning.

Training data format (JSONL)

Fine-tuning data for Bedrock is typically a JSON Lines (JSONL) file where each line is a standalone JSON object. Each example usually contains a prompt and a completion that demonstrate the desired input → output behavior. Example JSONL (each line is a separate JSON object):
You can provide a few dozen examples for basic customization or thousands for deeper domain alignment. The quality, diversity, and representativeness of examples have a direct impact on the fine-tuned model’s behavior.

Preparing S3 locations and IAM role

When using the Bedrock console or SDK, you will point the customization job at:
  • Training data (S3): e.g., s3://mybucket/customer-tone/train.jsonl
  • Output location (S3): e.g., s3://mybucket/customer-tone/output/
  • IAM role: a role with permissions to read the training S3 object and write job output
Example values you might supply in the console:
The IAM role must include read access to the training S3 URI and write access to the output S3 bucket.

Creating a customization (fine-tuning) job with boto3

Use the Bedrock control-plane client (bedrock) to create the customization job. For inference, use the Bedrock Runtime client (bedrock-runtime) — see the callout below.
When creating the SDK client, use the Bedrock control-plane API (service name bedrock) for operations such as creating customization jobs. Use the Bedrock Runtime API (service name bedrock-runtime) only for inference requests.
Example: create a model customization job with boto3:

Key customization parameters

Notes on hyperparameters:
  • epochCount: number of passes over the dataset.
  • batchSize, learningRate, learningRateWarmupSteps: tune to control convergence and stability.
  • The best values depend on dataset size, base model, and desired trade-offs (quality vs. cost/time).

Hosting options and ARNs

After successful customization, your model artifacts appear in your account under custom models (not the public/shared catalog). You can host the model in two primary ways:
  • Serverless (on-demand): call the custom model ARN directly for inference. Ideal for variable, low-volume usage.
  • Provisioned throughput: deploy a provisioned model contract and use the provisioned model ARN when invoking inference. This provides predictable capacity for production workloads. Note: you are billed for provisioned capacity whether or not it is used.
Table: hosting options After hosting, use the Bedrock Runtime API for inference requests (e.g., invoke_model).

Invoking a hosted (provisioned) model with boto3

Example using the Bedrock Runtime client. Replace provisioned_model_arn with your provisioned model ARN (or use the custom model ARN for on-demand).
When invoking:
  • Use lower temperature for more deterministic responses.
  • Optionally include generation constraints (max tokens, stop sequences) in the textGenerationConfig depending on the runtime schema.

What to expect from fine-tuning

Benefits of fine-tuning include:
  • More consistent outputs: the model learns the mapping you provided in training examples.
  • Reduced prompt complexity: fewer prompt-engineering tricks are often needed.
  • Better alignment with business needs: top-level behavior and style can be internalized.
  • Improved user experience: outputs more closely match real-world expectations.
A presentation slide titled "Results" with four numbered panels, each containing a circular icon. The panels read: "More consistent outputs," "Reduced prompt complexity," "Better alignment with business needs," and "Improved user experience."
To summarize succinctly: fine-tuning teaches the model; prompting only guides it. Fine-tuning updates (a subset of) model weights so the behavior demonstrated in your training examples becomes internalized. High-quality training data yields better outcomes.
A presentation slide titled "Key Takeaway" showing the point: "Fine-tuning teaches the model, prompting only guides it." The slide has a dark blue left panel and a light gray area with a blue "01" marker.
Invest time in curating training examples that are representative, diverse, and labeled with the exact tone and behaviors you want the model to reproduce.

Next steps: multimodal models (text + images)

The next lesson explores multimodal capabilities: combining text prompts with image inputs, constructing multimodal examples, and running inference across text + image modalities.
A presentation slide titled "What's Next? Multimodal capabilities (text and images)." To the right is a teal icon of a stylized brain with circuit lines on a dark blue curved background.
We will include practical code snippets for handling image inputs, tips for multimodal JSONL formatting, and examples of combining text and visual context to improve downstream application behavior.
Tip: Start with a small dataset and conservative hyperparameters to validate workflows and end-to-end permissions before scaling to larger training sets and longer epoch counts.

Watch Video