Skip to content

docs: add DSPy prompt-optimization learnings and adoption roadmap - #1448

Open
wildcard wants to merge 2 commits into
mainfrom
claude/dspy-caro-learnings-3lbw7l
Open

wildcard wants to merge 2 commits into
mainfrom
claude/dspy-caro-learnings-3lbw7l

Conversation

@wildcard

@wildcard wildcard commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Description

Research document: what stanfordnlp/dspy (v3.3.0) teaches about caro's prompt + evaluation architecture, and a phased adoption roadmap. Adds one file: docs/research/dspy-prompt-optimization.md.

Motivation

caro's quality ceiling on small local models (default Qwen2.5-Coder-1.5B Q4) is set by hand-tuned system prompts, iterated via the manual prompt-tuner loop. DSPy's core idea — the prompt is a compiled, versioned artifact optimized against a metric and a dataset, not hand-edited source — is exactly the discipline caro is missing. Exploration confirmed every ingredient already exists in the repo (~290 eval cases, a 5k-line harness, a chi-square A/B engine, a versioned prompt registry, per-platform few-shot libraries) but none of it is connected into an optimization loop.

The motivating example found during research: three sources of truth disagree on "list all files in the current directory" — the shipped embedded prompt teaches ls (embedded_backend.rs:221), the dead few-shot library says ls -a (smollm_prompt.rs:561), and the eval dataset expects ls -la (correctness-001). Nothing in the build detects this.

Changes Made

  • Add docs/research/dspy-prompt-optimization.md (docs-only, ~500 lines):
    • §1 DSPy primer pinned to v3.3.0: signatures / modules / adapters / optimizers (BootstrapFewShot, MIPROv2, GEPA, BootstrapFinetune), the program.save() JSON bridge that lets Python-side optimization feed a Rust runtime
    • §2 Evidence of caro's current state, every claim verified on main with file refs: 8 divergent inline create_system_prompt() bodies, dead src/prompts/ machinery, disconnected eval/A-B/registry, missing runtime feedback loops (no regeneration on final safety block; confidence_score is a per-backend constant; _max_iterations unused), the truncated prompt-tuner skill
    • §3 Eight ranked learnings with concrete changes, effort, and payoff — including a proposed prompt-artifact JSON schema and an explicitly-untested optimize.py sketch
    • §4 Four-phase roadmap with PR shapes, touchpoints, an exit criterion (compiled artifact must beat the hand-tuned prompt on a held-out split), and 11 proposed follow-up issues (not filed)
    • §5 Considered and rejected (dspy-rs runtime dep, Python sidecar, replacing the Rust harness, big-bang src/prompts/ rewrite)
    • §6 Risks and guardrails — notably that safety patterns are never in the optimizer's search space
  • Corrects the record on WP10-11: Prompt Engineering Framework (Versioning & A/B Testing) #517: it was closed as completed on 2026-01-17, but its own "Current State" list (prompts hard-coded in backends, no versioning, no systematic comparison) is still true on main today

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (code restructuring without changing behavior)
  • Documentation update (changes to docs, comments, or guides)
  • Performance improvement (makes code faster or more efficient)
  • Test coverage (adds or improves tests)
  • CI/CD or tooling (changes to build, release, or development tools)

Checklist

Code Quality

  • cargo fmt --all — N/A, no Rust changes
  • cargo clippy -- -D warnings — N/A, no Rust changes
  • cargo test — N/A, no Rust changes
  • cargo audit — N/A, no dependency changes

Testing

  • Tests added — N/A (docs-only)
  • Every repo claim (file paths, line numbers, function names, dataset counts, CI gate behavior, issue WP10-11: Prompt Engineering Framework (Versioning & A/B Testing) #517 state) re-verified against main before commit
  • Every external link (dspy repo, dspy.ai docs incl. GEPA and saving pages, DSRs repo, crates.io) fetched and confirmed to resolve

Documentation

  • Doc placed in docs/research/ following the existing kebab-case convention (gh-dash-tui-fundamentals.md, kavana-ball-interaction.md)
  • Fast-moving claims date-stamped (DSPy version, doc date)
  • CHANGELOG.md — not updated; research docs have not historically been changelog entries. Happy to add under Internal if preferred.

TDD Workflow

  • N/A (docs-only)

Breaking Changes

None. No code, config, or public API changes.


Related Issues and Specs

  • Related to WP10-11: Prompt Engineering Framework (Versioning & A/B Testing) #517 (WP10-11: Prompt Engineering Framework) — closed 2026-01-17; this doc proposes the successor work (Phase 2 harness)
  • Related to thoughts/shared/plans/evaluation-harness-maturity-milestone.md (Phase 2: Prompt Engineering Framework)
  • Prior art referenced: tests/evaluation/src/prompt_comparison.rs, tests/evaluation/prompts/v1.0/, src/prompts/minimal.rs, src/evaluation/sft_export.rs

Performance Impact

None (docs-only).


Screenshots / Examples

N/A — no CLI behavior changes.


Testing Evidence

Docs-only PR: no test suite applies. Verification performed:

  • Spot-checked the two load-bearing claims by reading the source directly: the embedded create_system_prompt() body (src/backends/embedded/embedded_backend.rs:183-268) and tests/evaluation/dataset.yaml correctness-001
  • Confirmed _max_iterations: 2 is underscore-prefixed/unused (src/agent/mod.rs:29,77), the final safety pass at src/cli/mod.rs:836-838 has no regeneration path, and confidence_score constants per backend (embedded_backend.rs:511, static_matcher.rs:1901, etc.)
  • Confirmed .github/workflows/evaluation.yml runs the harness under || true and skips the threshold check for 0.0 baselines
  • Confirmed .claude/skills/prompt-tuner/SKILL.md is 107 lines ending in an unclosed code fence, and data/evals/default.yaml (cited by src/prompts/minimal.rs) does not exist
  • Confirmed issue WP10-11: Prompt Engineering Framework (Versioning & A/B Testing) #517 state via the GitHub API (closed, completed, 2026-01-17, no linked PRs)

Additional Context

Technical Decisions

  • Docs-only, no prototype harness. This container cannot run local models, so an optimize.py would ship untested. The doc embeds the artifact schema and a clearly-marked sketch; the real harness lands in Phase 2 with a recorded before/after run as evidence.
  • No dspy-rs dependency proposed. The optimizer is the valuable part and it runs offline; caro's runtime needs (render + parse + bounded retry) are a few hundred lines of Rust. If revisited, it goes through .claude/rules/external-sdk-integration.md first.
  • Safety is out of the optimizer's scope by design. The doc mandates that a compiled prompt which raises pass rate by producing commands the validator then blocks is scored worse, not better.
  • This is internal tooling / evaluation research, so .claude/rules/validation-discipline.md gates do not apply; Phase 1–3 feature PRs will carry feature-evidence.md artifacts.

Future Work

Eleven proposed follow-up issues are listed in §4 of the doc (not filed — owner's call). The two cheapest, highest-leverage next steps are diagnostic failure_reason feedback in the evaluators (L2) and bounded regeneration when the final safety pass blocks (L4). Boy-scout item also listed: repair the truncated prompt-tuner SKILL.md.

Questions for Reviewers

  • Should ADR-017 (versioned prompt artifacts) be drafted now alongside this doc, or wait for Phase 1?
  • Is tools/dspy-harness/ (beside tools/mlx-finetune/) the right home for Python dev tooling, or is there a preferred location?

Reviewer Checklist

  • Documentation is clear and complete
  • Repo claims match main (file refs, counts, CI behavior)
  • Roadmap phasing and effort estimates are reasonable
  • Changes align with project specifications

By submitting this PR, I confirm that:

  • My changes follow the style guidelines of this project (see AGENTS.md)
  • I have performed a self-review of the document
  • My changes generate no new warnings or errors (docs-only)
  • I have read and followed the contributing guidelines
  • I agree to the Code of Conduct

🤖 Generated with Claude Code

https://claude.ai/code/session_01WwYKNGPu4RYoe6dipMkSka


Generated by Claude Code


Summary by cubic

Adds a research doc mapping DSPy's prompt-optimization concepts onto caro's prompt and evaluation architecture, with a phased adoption roadmap to close the gap between hand-tuned prompts and an optimization loop.

  • Documents eight ranked learnings from DSPy v3.3.0, including compiled prompt artifacts, metric-with-feedback, and an offline optimizer harness.
  • Verifies every claim against main: eight divergent inline prompt bodies, dead structured prompt machinery, the CI harness scoring only the static matcher, and three sources of truth disagreeing on a basic query.
  • Proposes a four-phase roadmap whose exit criterion requires a paired McNemar test on a held-out split, and explicitly keeps safety patterns out of the optimizer's search space.
  • Corrects the record on WP10-11: Prompt Engineering Framework (Versioning & A/B Testing) #517 — closed as completed but its goals remain unmet — and connects the work to open umbrella issue Improve embedded model command generation quality (prompt engineering + fallback) #798.

Written for commit 9851175. Summary will update on new commits.

Review in cubic

Research document mapping stanfordnlp/dspy (v3.3.0) concepts onto caro's
prompt and evaluation architecture, with a phased adoption plan.

Key findings (all verified against main):
- Production prompts are 8 hand-edited inline strings, one per backend,
  while the structured src/prompts/ machinery is dead code.
- Three sources of truth disagree on "list all files in the current
  directory": shipped prompt says `ls`, dead few-shot library says
  `ls -a`, eval dataset expects `ls -la`.
- ~290 eval cases, a chi-square A/B engine, and a versioned prompt
  registry exist but are not connected into any optimization loop.
- Runtime feedback loops are missing where they matter most: the final
  safety block has no regeneration hook and confidence_score is a
  per-backend constant.

Eight ranked learnings (compiled prompt artifacts, metric-with-feedback,
offline GEPA/BootstrapFewShot harness, bounded Refine on safety failure,
platform demos as data, shared output adapter, honest confidence,
BootstrapFinetune tie-in), a four-phase roadmap, rejected alternatives
(dspy-rs runtime dep), risks/guardrails, and 11 proposed follow-up issues.

Docs-only; no code changes. Related to #517.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwYKNGPu4RYoe6dipMkSka
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
caro-foss-website Ready Ready Preview Sep 12, 2026 10:53pm UTC
5 Skipped Deployments
Project Deployment Actions Updated
caro-docs Ignored Ignored Sep 12, 2026 10:53pm UTC
caro-slides Ignored Ignored Sep 12, 2026 10:53pm UTC
caro-storybook Ignored Ignored Sep 12, 2026 10:53pm UTC
cmdai Ignored Ignored Sep 12, 2026 10:53pm UTC
cmdai-saas Ignored Ignored Sep 12, 2026 10:53pm UTC

Request Review

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@github-actions

Copy link
Copy Markdown
Contributor

Solid work! 💪

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T21:12:36.581675Z 6fb4854 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added documentation Improvements or additions to documentation size/XS Extra small PR (< 10 lines) labels Sep 11, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread docs/research/dspy-prompt-optimization.md Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fb48548cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/research/dspy-prompt-optimization.md Outdated
Comment thread docs/research/dspy-prompt-optimization.md Outdated
Comment thread docs/research/dspy-prompt-optimization.md Outdated
Comment thread docs/research/dspy-prompt-optimization.md Outdated
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Website Claims Verification Report

Run ID: 34723931702
SHA: f9efbd4
Date: 2026-09-12

Platform Results

claims-report-macos-latest

{
  "suite": "website-claims",
  "platform": "macos-latest",
  "timestamp": "2026-09-12T22:55:33Z",
  "passed": 84,
  "skipped": 0,
  "warnings": 1,
  "run_id": "34723931702",
  "sha": "f9efbd401b36db6972197283c61f29f34de167bc"
}

claims-report-ubuntu-latest

{
  "suite": "website-claims",
  "platform": "ubuntu-latest",
  "timestamp": "2026-09-12T22:56:19Z",
  "passed": 84,
  "skipped": 0,
  "warnings": 1,
  "run_id": "34723931702",
  "sha": "f9efbd401b36db6972197283c61f29f34de167bc"
}

Documentation

Next Steps

  1. Review warnings and address any gaps
  2. Update website if claims are inaccurate
  3. Implement missing features if claims are aspirational

@wildcard wildcard added the path:auto caro-merge-review-integrate dispatcher classification label Sep 12, 2026
Corrections from PR #1448 review (cubic, Codex), each verified against main:

- Dataset inventory: JSON cases live under tests/evaluation/datasets/**
  (5 files, 80 cases), not a root datasets/ dir; test_cases.toml has 55
  cases, not 56.
- Harness backend gap: tests/evaluation/main.rs rejects the CI matrix's
  embedded-smollm/embedded-qwen names and registers only StaticMatcher
  for the rest, so no LLM backend has ever been scored by the CI eval
  workflow. Added to §2.3 and as a Phase 1 prerequisite.
- Metric attribution: the CI target imports caro::evaluation, so the gate
  metric is the boolean one in src/evaluation/evaluators/; the graded
  ladder in tests/evaluation/src/evaluator.rs belongs to the unlinked
  caro-evaluation crate. L3 harness must mirror the former.
- Paired comparison: prompt_comparison::chi_square_test is unpaired;
  the Phase 3 exit criterion now requires McNemar's (or paired bootstrap).
- Added open umbrella issue #798 (embedded prompt quality) to §2.3 and
  the follow-up list, now 13 items.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WwYKNGPu4RYoe6dipMkSka

Copy link
Copy Markdown
Owner Author

Addressed the review in 9851175 — all five threads resolved:

  • Dataset inventory (cubic, Codex): JSON cases live under tests/evaluation/datasets/** (5 files, 80 cases); test_cases.toml has 55 cases, not 56.
  • Metric attribution (Codex): the CI target imports caro::evaluation, so the gate metric is the boolean one in src/evaluation/evaluators/; the graded ladder in tests/evaluation/src/evaluator.rs belongs to the unlinked caro-evaluation crate. §2.3, L3, and the harness sketch now mirror the right one.
  • Harness backend gap (Codex): tests/evaluation/main.rs rejects embedded-smollm / embedded-qwen and registers only StaticMatcher for the accepted names, so no LLM backend has ever been scored by the eval workflow. Added to §2.3 and as a Phase 1 prerequisite.
  • Paired comparison (Codex): the Phase 3 exit criterion now requires McNemar's (or a paired bootstrap) instead of the unpaired chi_square_test.
  • Added open umbrella issue Improve embedded model command generation quality (prompt engineering + fallback) #798 to §2.3; the follow-up list is now 13 items.

CI: the only red check, Security Audit, is cargo audit failing on h2 0.3.27 / 0.4.13 (RUSTSEC-2026-0258) in Cargo.lock. Unrelated to this docs-only change and failing identically on main — see the scheduled run on be07b22. Will re-run once the base is fixed.

Filed #1451 for the first follow-up (L2, diagnostic evaluator feedback).


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation path:auto caro-merge-review-integrate dispatcher classification size/XS Extra small PR (< 10 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants