# Better Data for AI Agents: Data Selection & Quality | Stanford CS329Z Lecture 11 with John Yang

## Executive summary

This lecture details advanced strategies for data selection and quality in training AI agents, arguing that 'better data' often surpasses 'more data' when compute resources are constrained. The process involves a multi-stage funnel: ensuring task validity (non-ambiguous, non-loopholes), confirming learnability (providing a useful learning signal), and finally, selecting high-quality trajectories. Techniques discussed include automated filtering, contrastive learning using negative examples, and self-evolving curriculum design.

## Key takeaways

- Success Bias is Detrimental: Fine-tuning agents only on successful trajectories biases the data toward what the teacher model can already solve, potentially missing interesting failed trajectories or problem distributions. Failed trajectories, when labeled or corrected, can improve results.
- The Learnability Constraint: A reinforcement learning task is considered 'learnable' if the model succeeds sometimes but not always (e.g., 1 to 7 times out of 8 rollouts), providing a useful learning signal. Tasks that are too easy or too difficult are filtered out.
- Quality Filtering Outperforms Quantity: In certain scenarios, a small, curated dataset (e.g., 5K high-quality tasks) can outperform a much larger, unfiltered dataset (e.g., 8K tasks) due to the increased reliability and fidelity of the data.
- Negative Trajectories are Valuable: Training on negative or failure trajectories, especially when combined with contrastive objectives, can help encompass a larger distribution of tasks and explicitly teach the model what behaviors to avoid.

## Technical details

- SWE-bench Verified Process: SWE-bench Verified was created by professional developers who annotated 1,700 tasks to check for underspecified issues and unfair tests, resulting in a curated set of 500 tasks. This process ensures verification reliability and problem statement alignment.
- Automated Filtering Mechanisms: Automated quality checks include running reference solutions multiple times to remove flaky tests, confirming the starting state fails, flagging hard-coded expectations, and using an LLM monitor to catch leakage and reward hacking.
- Trajectory Filtering (SweetPrime): SweetPrime focuses on filtering within a single trajectory, identifying and masking out actions that are low quality (e.g., spurious file editing, cascading errors) to improve SFT quality.
- Curriculum Learning (Self-Evolving): In both web RL and coding agent contexts, self-evolving curricula involve re-filtering the task pool after RL steps. Tasks that were previously too difficult become solvable, and these new tasks are introduced into the training mix.

## Practical implications

- When operating under a fixed compute budget, prioritize data quality (filtering) over sheer quantity to maximize the yield of training steps.
- Implement robust CI/CD checks (e.g., running reference solutions multiple times) to detect and remove flaky tests before training begins.
- Use LLM monitoring systems to detect reward hacking or leakage during training runs, ensuring the agent is solving the task the 'right way'.
- Employ curriculum learning by iteratively re-evaluating the task difficulty distribution as the model improves.

## Topics

AI Agents, Reinforcement Learning, Data Quality, Benchmarking, Machine Learning Operations (MLOps), SWE-bench Verified, Code World Models, Code Midas, SweetPrime

Source: https://www.youtube.com/watch?v=y2cwbmOy12U
