Reinforcement Fine-Tuning (RFT) on Amazon Bedrock lets you customize large language models (LLMs) through an iterative feedback loop where the model learns from evaluations of its own responses using OpenAI-compatible APIs.
Until recently, fine-tuning was synonymous with Supervised Fine-Tuning (SFT), which requires thousands of perfect input-output pairs. With the February 2026 update, Bedrock now supports RFT for open-weight models like OpenAI GPT OSS 20B and Qwen 3 32B. This shift means you can now ship high-performance, specialized models (like a math tutor or a code reviewer) using a small set of prompts and a programmatic "reward function" rather than a massive, manually labeled dataset.
Why this matters for builders
Reinforcement Fine-Tuning (RFT) lets you improve model accuracy on complex tasks by rewarding "good" answers and penalizing "bad" ones using a Lambda-based reward function.
This is a game-changer for vibe coders because:
- Data Efficiency: You don't need 10,000 "perfect" answers. You need a set of prompts and a way to check if the answer is right (e.g., running a unit test or checking a math result).
- Standardized Workflow: You can use the familiar OpenAI Chat Completions data format and APIs, reducing the friction of moving between different AI ecosystems.
- Automation: Bedrock handles the heavy lifting—generating multiple candidate responses, scaling the reward computation via Lambda, and optimizing the model using the GRPO (Group Relative Policy Optimization) algorithm.
When to use it
- Verifiable Tasks: Use it for math (GSM8K), logic puzzles, or code generation where correctness can be checked automatically.
- Multi-turn Conversations: When the model needs to learn specific persona traits or strategic decision-making over several prompts.
- Low-Data Scenarios: When you have plenty of prompts but very few "gold standard" human-written answers.
- Constraint Following: When a model must strictly adhere to specific formats (JSON, Markdown) or length requirements.
Phase 1: Shape the spec and dataset
The first step isn't coding; it's defining what "success" looks like. In RFT, your dataset consists of prompts. Bedrock supports the OpenAI Chat Completions format (JSONL).
The Vibe Strategy:
- Gather 100–500 prompts that represent your specific use case.
- Format them as a
.jsonlfile. - Upload the dataset to an Amazon S3 bucket.
Starter Prompt for your Coding Assistant:
"I am preparing a dataset for Amazon Bedrock Reinforcement Fine-Tuning. I have a CSV of math word problems. Write a Python script to convert this CSV into an OpenAI-compatible JSONL format. Each line should follow the
{"messages": [{"role": "user", "content": "..."}]}structure. Ensure the output is saved to a file namedtrain.jsonl."
Phase 2: Deploy the Reward Function
The reward function is the "brain" of the training process. It is a Python-based AWS Lambda function that receives the model's response and returns a numerical score.
Validation Logic:
- Score of 1.0: Perfect answer.
- Score of 0.0: Incorrect or poorly formatted.
- Partial Credit: You can return values between 0 and 1 if the answer is "close."
Example Reward Function (Math Validation)
This is a conceptual template based on the GSM8K example:
import json
import re
def lambda_handler(event, context):
# 'event' contains the model response and the ground truth
# Structure follows OpenAI format provided by Bedrock
model_response = event['messages'][-1]['content']
ground_truth = event['metadata']['ground_truth']
# Simple regex to extract a number from the model's response
match = re.search(r"The answer is (\d+)", model_response)
if match:
extracted_answer = match.group(1)
if extracted_answer == str(ground_truth):
return {"score": 1.0}
else:
return {"score": 0.0}
return {"score": -0.1} # Penalty for bad formatting
Note: Ensure your SageMaker AI execution role has InvokeFunction permissions for this Lambda.
Phase 3: Kick off the RFT Job
You don't need a complex SDK if you are comfortable with the OpenAI-compatible API. You will point Bedrock to your base model (openai.gpt-oss-20b or qwen.qwen3-32b), your S3 data, and your Lambda ARN.
API Request Template
curl https://bedrock-runtime.us-east-1.amazonaws.com/v1/fine_tuning/jobs \
-H "Content-Type: application/json" \
-d '{
"model": "openai.gpt-oss-20b",
"training_file": "s3://my-bucket/train.jsonl",
"reward_function": {
"function_arn": "arn:aws:lambda:us-east-1:1234567890:function:my-reward-logic"
},
"hyperparameters": {
"learning_rate": "1e-5",
"iterations": "2"
}
}'
Phase 4: Validate and Ship
One of the best features of Bedrock RFT is that once the job completes, the model is available for on-demand inference immediately. There is no manual deployment or "provisioned throughput" setup required for initial testing.
How to validate:
- Monitor CloudWatch: Check the logs for your reward function. If you see consistent 0.0 scores, your regex or validation logic might be failing to parse the model's output.
- Check Convergence: Look at the Bedrock console or CloudWatch metrics. If the "Reward" metric is trending upward, the model is successfully learning your criteria.
- Run Inference: Use the standard OpenAI Chat Completions client to talk to your new model ID.
Pitfalls and guardrails
What if my reward function is slow?
AWS documentation suggests reward functions should execute within seconds. If your Lambda takes minutes (e.g., by calling external APIs or running complex simulations), the training job may time out or become prohibitively expensive. Aim for pure-Python logic or efficient database lookups.
How do I prevent the model from "gaming" the reward?
This is a common reinforcement learning issue called "reward hacking." If you reward the model for "long answers," it will learn to write fluff.
- Guardrail: Combine multiple criteria. Reward the correct answer, but apply a small penalty for every 100 extra tokens used.
Why is my model not improving?
Check if your reward signal is "sparse." If your model never accidentally gets the right answer, it never receives a 1.0, and it has nothing to learn from.
- Fix: Start with a model that is already somewhat capable of the task (SFT first if necessary), or make your reward function more "shaped" (give partial credit for the right steps).
What to do next
- Select your model: Choose
qwen.qwen3-32bfor logic/math oropenai.gpt-oss-20bfor general purpose. - Draft your Lambda: Write a script that can programmatically verify your goal.
- Run a pilot: Use a tiny dataset of 20 prompts to ensure the Lambda and Bedrock connection is working before running a full job.
- Monitor: Use Amazon CloudWatch to track the "policy loss" and "reward score" during the training run.
Sources
- Reinforcement fine-tuning on Amazon Bedrock with OpenAI-Compatible APIs: a technical walkthrough
- Amazon Bedrock reinforcement fine-tuning adds support for open-weight models with OpenAI-compatible APIs
- Customize a model with reinforcement fine-tuning in Amazon Bedrock
- Fine-tune open-weight models using OpenAI-compatible APIs

