What this thread does
Do first: use from instructor.batch import BatchProcessor.
When you need it
Use file-based batch processing for a large collection of extraction requests or an audit trail. The page demonstrates a User schema and separate submission and result retrieval.
Steps
1. Import the batch processor and define the page's result schema:
from instructor.batch import BatchProcessor
from pydantic import BaseModel
class User(BaseModel):
name: str
age: int
processor = BatchProcessor("openai/gpt-6-luna", User)
2. Build the page's two conversations:
messages_list = [
[
{"role": "system", "content": "Extract user information from text."},
{"role": "user", "content": "Hi, I'm Alice and I'm 28 years old."},
],
[
{"role": "system", "content": "Extract user information from text."},
{"role": "user", "content": "Hello, I'm Bob, 35 years old."},
],
]
3. Write the JSONL file and submit it:
processor.create_batch_from_messages(
file_path="batch_requests.jsonl",
messages_list=messages_list,
max_tokens=200,
temperature=0.1,
)
batch_id = processor.submit_batch("batch_requests.jsonl")
print(f"Batch job submitted: {batch_id}")
4. Retrieve results only after the completion status:
status = processor.get_batch_status(batch_id)
if status["status"] == "completed":
from instructor.batch import extract_results
all_results = processor.retrieve_results(batch_id)
for user in extract_results(all_results):
print(f"Name: {user.name}, Age: {user.age}")
Check it worked
The example prints the submitted batch ID, then each extracted name and age after completion. Inspect error records too; the page exposes filter_errors for failed requests.
Limits
Running jobs cannot be retrieved. BatchProcessor supports OpenAI, Anthropic, and Mistral only. The OpenAI strict batch path requires all named output fields and does not support arbitrary-key dictionaries. The page does not name a version for this OpenAI flow; its Mistral SDK requirements concern a different provider.
Not for: Google GenAI requests through instructor.from_provider; BatchProcessor does not support that provider.
Sources
- Batch Processing, instructor documentation, read 2026-11-24: "Jobs that are still running cannot be retrieved."
Checked
2026-11-24; read <https://python.useinstructor.com/concepts/batch/index.md>; no command was run.
Started from a post by @instructor, packaged by the editor. Original post