Skip to content

expressive constraints with feedback #44

Open

Description

@darinkishore

suggestion :

i think it would be cool if we allow for per-field and per-signature validation with custom code as well (eg: tool_calls must conform to allowed tools schema) and allow returning help-text to the LLM for the things which it didn't exactly conform to on retries.

this could look like a fn validate() and maybe an arg auto_retry (or handle it like cot) with specified retry counts.
validate should return natural language feedback about what exactly was wrong.

ie: two return types, return one of either, if x -> j,k,l must be present and valid, if y -> w must be present, q/r are optional but if including one u must include the other.

this feels useful because we're giving ourselves much more expressiveness and flexibility by bringing in BAML's schema .

just a brainstorm.

Activity

  1. darinkishore commented on Feb 12, 2026

    @darinkishore
    CollaboratorAuthor

    Codebase audit — what's done vs what's left

    Done:

    • #[baml(check(label = "...", expr = "..."))] — per-field constraint checks, surfaced as ResponseCheck in Parsed<T>.checks
    • #[baml(assert(label = "...", expr = "..."))] — hard constraints that fail parsing (BamlParseError::ConstraintAssertsFailed)
    • Parsed<T> returns { value, baml_value, flags, checks, explanations } — full diagnostic bundle

    Not done — the feedback-to-LM retry loop:

    • When constraints fail, the adapter should be able to re-prompt the LM with natural language feedback about what was wrong
    • This would look like: parse → constraints fail → format failure reasons as user message → re-send to LM → parse again
    • The ResponseCheck already has label and status — needs a feedback: String or the label itself used as feedback
    • The retry should be configurable: max_retries, and whether to retry on check failures (soft) vs only assert failures (hard)

    Where this hooks in:

    • Predict::forward() in predictors/predict.rs is where the call + parse happens
    • The retry loop would wrap the existing adapter.format() → lm.call() → adapter.parse() sequence
    • ChatAdapter::parse() already returns Parsed<T> with constraint results — the information is there, just not fed back

    Design question: should retry-with-feedback live in Predict (module-level) or in a separate ValidatedPredict wrapper module? The DSPy pattern would be module-level with a configurable retry policy.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions