Preserve native validation failure details

This commit is contained in:
2026-11-25 15:03:16 +00:00
parent adb198e19f
commit 3650049c33
8 changed files with 114 additions and 11 deletions

View File

@@ -0,0 +1,40 @@
package pipeline
import (
"errors"
"fmt"
"strings"
"go.maximumdirect.net/promptkit"
)
// NativeValidationError describes a completed native content check that did
// not pass. It is distinct from a native operational error such as failure to
// prepare or run validation.
type NativeValidationError struct {
Validation promptkit.ValidationResult
}
func (e *NativeValidationError) Error() string {
if len(e.Validation.Errors) == 0 {
return "native output did not satisfy its contract"
}
return fmt.Sprintf("native output did not satisfy its contract: %s", strings.Join(e.Validation.Errors, "; "))
}
// CheckNativeResult preserves an actual native error and rejects an absent or
// structurally unusable result before any domain interpretation takes place.
func CheckNativeResult(result *promptkit.RunResult, err error) error {
if err != nil {
return err
}
if result == nil {
return errors.New("native execution returned no result")
}
if result.Validation.Status == promptkit.ValidationFailed || !result.Validation.IsValid {
validation := result.Validation
validation.Errors = append([]string(nil), validation.Errors...)
return &NativeValidationError{Validation: validation}
}
return nil
}