Skip to content

Add typed validation callbacks and corrective retries - #136

Open
arthurianresolve wants to merge 110 commits into
krypticmouse:mainfrom
arthurianresolve:fix-validation-feedback
Open

arthurianresolve wants to merge 110 commits into
krypticmouse:mainfrom
arthurianresolve:fix-validation-feedback

Conversation

@arthurianresolve

@arthurianresolve arthurianresolve commented Nov 10, 2026 •

Copy link
Copy Markdown

Summary of Fix

Stacked on the public-export fix, which includes #134. Merge those changes before this PR.

  • Add Predict::validated() and ValidatedPredict<S> for Rust callbacks that receive the typed input and complete typed output.
  • Collect field-level and cross-field validation failures as natural-language feedback and append them to the conversation before another attempt.
  • Retry parse failures and hard assertions; optionally promote failed soft checks with retry_failed_checks(true).
  • Bound total attempts, including the initial call, with a default of one. Return typed validation errors with the last raw response on exhaustion.
  • Accumulate reported token usage across successful and exhausted validation attempts, including zero additional usage for cache hits.
  • Preserve scoped LM selection and optimizer leaf discovery. Reject multiple attempts on predictors with attached native tools before any execution, preventing repeated tool side effects.

Fixes #44

Why

Existing checks and assertions validate schema expressions, but applications also need custom Rust rules involving individual fields, relationships between fields, or the original input. Their error messages should help the LM correct the response within a bounded conversation.

Callbacks run after typed parsing. Provider, configuration, conversion and strict-replay errors return immediately; transport retries remain the LM's responsibility. A single attempt can validate the final output of a tool-enabled predictor. Descriptions of tool calls in ordinary typed output can also be checked by callbacks.

History and trace spans retain the underlying predictor calls. Custom validation does not rewrite a successful parser span, and callbacks are not serialized with optimizer state.

Related work

Testing

  • Final integrated cache-enabled release checks: 61 tests passed using --no-default-features --features cache (three live tests excluded from this offline run). This covers invocation history, persistent storage, tool-loop limits, native/scalar output and trace/history parity.

  • Integrate the current Add provider-native structured output and scoped sampling #121/Decouple execution history and feature-gate response caching #134 typed special fields and persistent interaction storage through the existing prerequisite stack.

  • Validation regressions pass with caching compiled out and with the cache feature. Coverage includes field/cross-field callbacks, corrective conversation content, parse/assertion repair, optional soft checks, exhaustion, cumulative usage, cache hits, LM overrides, leaf discovery and rejection before tool side effects.

  • The resolved stack at 2b4590f0174dc05582347b8da75b6b58fbce9ca0 passed 209 tests with --no-default-features and 247 with default data/cache features (2 live tests ignored per offline run). These are focused library and integration suites, not the full workspace test suite. Later ancestry-only integration merges preserve the validated source trees.

  • Native nested-constraint and history/configuration integration tests pass on that same resolved stack.

  • git diff --check — passed.

AI Disclosure

  • OpenAI Codex assisted with implementation, tests, and PR drafting.
  • all fixes and drafts have been human-architected, human-directed and human-reviewed before publication of PR requests.

…-structured-output

# Conflicts:
#	crates/dspy-rs/src/core/lm/mod.rs
#	crates/dspy-rs/src/trace/span.rs
@mintlify

mintlify Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 1398cfe.

Approve preview

arthurianresolve added a commit to arthurianresolve/DSRs that referenced this pull request Nov 19, 2026
Integrate krypticmouse#136 — Add typed validation callbacks and corrective retries

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expressive constraints with feedback

1 participant