No account, no key:
pip install 'runapprentice[optimize]' then apprentice optimize <task> --local --data golden.csv runs the same optimization on your machine with your own OpenAI key. Add [local] for MLX fine-tuning on Apple silicon. No golden dataset yet? An API key also lets Apprentice generate a starter set and route rows to a subject-matter expert for review, and tracks every run in the console.Install
Inside a project, where your code also imports the SDK:Set your key
base_url (or APPRENTICE_BASE_URL) to point at a self-hosted backend.
Run it
golden.csv needs an input column and an output column. For a JSON task, the output is the exact JSON you want back.
What you get
report.baseline_score and report.optimized_score are field-level scores on rows the optimizer held out, so treat the result as proof for this dataset, not a universal benchmark. report.optimized_prompt is the rewritten instruction. Send it with client.prompts.get(task).messages(...) rather than pasting it: on its own it has no slot for your input, so a hand-rolled call can drop the input without erroring.
If
optimized_score does not beat baseline_score, that is a real result, not a failure of the tool. Add cleaner verified rows, or pick a metric that fits the task, then run again. We never report a gain that is not there.Next
JSON extraction, end to end
The same flow with a real dataset and the optimized prompt pulled back into code.
Capture from LangChain
Build the dataset from your live traffic instead of a CSV.