Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(agent): save incomplete input options and gate Run (#21366)

Sbaaoui Idriss8fc01ad53762
diff --git a/internal/agent/canvas/interrupt_resume.go b/internal/agent/canvas/interrupt_resume.go
index a458a481b2..43b935204d 100644
--- a/internal/agent/canvas/interrupt_resume.go
+++ b/internal/agent/canvas/interrupt_resume.go
@@ -131,6 +131,9 @@ func buildUserFillUpInterruptInfo(ctx context.Context, params map[string]any) ma
func UserFillUpNodeBody(cpnID string, params map[string]any) func(ctx context.Context, input map[string]any) (map[string]any, error) {
inputSpec := BuildInputSpec(params)
body := func(ctx context.Context, input map[string]any) (map[string]any, error) {
+ if err := runtime.ValidateUserFillUpOptions(params, false); err != nil {
+ return nil, runtime.NewUserFacingError(err.Error())
+ }
// Resume branch: the orchestrator decorated ctx with
// compose.ResumeWithData(ctx, interruptID, userInput).
// isResumeFlow is true when THIS node is the explicit target;
diff --git a/internal/agent/canvas/node_body.go b/internal/agent/canvas/node_body.go
index 6e3cada5fb..6eaa4c3dc1 100644
--- a/internal/agent/canvas/node_body.go
+++ b/internal/agent/canvas/node_body.go
@@ -144,6 +144,9 @@ func buildNodeBodyWithOptions(ctx context.Context, cpnID, name, displayName stri
// (compose.Interrupt) and resumes from the orchestrator's
// compose.ResumeWithData call.
if strings.EqualFold(name, "UserFillUp") {
+ if err := runtime.ValidateUserFillUpOptions(params, false); err != nil {
+ return nil, runtime.NewUserFacingError(err.Error())
+ }
return UserFillUpNodeBody(cpnID, params), nil
}
if factory := resolveComponentFactory(ctx); factory != nil {
diff --git a/internal/agent/component/dynamic_params.go b/internal/agent/component/dynamic_params.go
index 6cbfb13aac..74ba9079a1 100644
--- a/internal/agent/component/dynamic_params.go
+++ b/internal/agent/component/dynamic_params.go
@@ -3,6 +3,7 @@ package component
import (
"errors"
"fmt"
+ "ragflow/internal/agent/runtime"
"strings"
)
@@ -16,7 +17,7 @@ func ValidateDynamicEntries(dsl map[string]any) error {
}
// ValidateDraftDynamicEntries allows unfinished Message content, DataOperations
-// entries, Invoke mappings, and Compiler configuration in saved drafts.
+// entries, Invoke mappings, Compiler configuration, and input options in saved drafts.
// All other checks remain unchanged.
func ValidateDraftDynamicEntries(dsl map[string]any) error {
return validateDynamicEntries(dsl, true)
@@ -94,7 +95,7 @@ func validateDynamicParams(component string, params map[string]any, draft bool)
case "variableaggregator":
return validateVariableAggregatorGroups(component, params)
case "userfillup":
- return validateInputOptions(component, params)
+ return runtime.ValidateUserFillUpOptions(params, draft)
case "exesql":
if err := validateExeSQLParams(params); err != nil {
return fmt.Errorf("[%s] %w", component, err)
@@ -251,21 +252,6 @@ func validateIterationOutputs(component string, params map[string]any) error {
return nil
}
-func validateInputOptions(component string, params map[string]any) error {
- if inputs, ok := params["inputs"].(map[string]any); ok {
- for key, raw := range inputs {
- entry, ok := raw.(map[string]any)
- if !ok {
- continue
- }
- if values, ok := entry["options"].([]any); ok && containsBlank(values) {
- return fmt.Errorf("[%s] inputs.%s.options does not support empty entries", component, key)
- }
- }
- }
- return nil
-}
-
func isBlank(value any) bool {
s, ok := value.(string)
return ok && strings.TrimSpace(s) == ""
diff --git a/internal/agent/component/dynamic_params_test.go b/internal/agent/component/dynamic_params_test.go
index 289be8f295..9399d1ec7d 100644
--- a/internal/agent/component/dynamic_params_test.go
+++ b/internal/agent/component/dynamic_params_test.go
@@ -101,7 +101,7 @@ func TestValidateDynamicEntries(t *testing.T) {
case "invoke variable row not a map", "invoke variable nil row", "invoke variable with numeric key", "invoke variables not an array", "invoke variables object":
invokeDraft = false
}
- if test.component["component_name"] == "Message" || test.component["component_name"] == "DataOperations" || test.component["component_name"] == "Compiler" || invokeDraft {
+ if test.component["component_name"] == "Message" || test.component["component_name"] == "DataOperations" || test.component["component_name"] == "Compiler" || invokeDraft || test.name == "input option" {
if draftErr != nil {
t.Fatalf("draft rejected unfinished entries: %v", draftErr)
}
diff --git a/internal/agent/component/userfillup.go b/internal/agent/component/userfillup.go
index e19d11af80..d32708f20d 100644
--- a/internal/agent/component/userfillup.go
+++ b/internal/agent/component/userfillup.go
@@ -55,15 +55,20 @@ var tipsPlaceholderPattern = regexp.MustCompile(`\{\{\s*([A-Za-z_][A-Za-z0-9_]*)
// userFillUpParam is the per-instance configuration for UserFillUp.
type userFillUpParam struct {
- EnableTips bool `json:"enable_tips"`
- Tips string `json:"tips"`
- LayoutRecognize string `json:"layout_recognize"`
+ EnableTips bool `json:"enable_tips"`
+ Tips string `json:"tips"`
+ LayoutRecognize string `json:"layout_recognize"`
+ Inputs map[string]any `json:"inputs"`
}
// Update copies a fresh params map into the receiver, applying defaults
// for any omitted keys. Returns nil on success (param validation is
// performed by Check, not here).
func (p *userFillUpParam) Update(conf map[string]any) error {
+ p.Inputs, _ = conf["inputs"].(map[string]any)
+ if err := runtime.ValidateUserFillUpOptions(conf, true); err != nil {
+ return err
+ }
if conf == nil {
conf = map[string]any{}
}
@@ -84,10 +89,13 @@ func (p *userFillUpParam) Update(conf map[string]any) error {
return nil
}
-// Check performs parameter validation. UserFillUp has no required
-// fields — any config is accepted and degrades gracefully on missing
-// template data. The method is kept to satisfy the ParamBase
-func (p *userFillUpParam) Check() error { return nil }
+// Check rejects incomplete option rows before execution.
+func (p *userFillUpParam) Check() error {
+ if p.Inputs == nil {
+ return nil
+ }
+ return runtime.ValidateUserFillUpOptions(map[string]any{"inputs": p.Inputs}, false)
+}
// AsDict returns the param as a plain map for serialization / debug.
func (p *userFillUpParam) AsDict() map[string]any {
@@ -118,6 +126,9 @@ func (u *UserFillUpComponent) Name() string { return u.name }
// output per form field. Inputs are expected under the top-level
// "inputs" key.
func (u *UserFillUpComponent) Invoke(ctx context.Context, db *gorm.DB, inputs map[string]any) (map[string]any, error) {
+ if err := u.param.Check(); err != nil {
+ return nil, runtime.NewUserFacingError(err.Error())
+ }
// State is required for the canvas ref grammar, but UserFillUp's
// tips substitution uses simple {{key}} placeholders resolved
// against the form input map. We still extract state so a
@@ -298,6 +309,9 @@ func init() {
if err := p.Update(params); err != nil {
return nil, err
}
+ if err := p.Check(); err != nil {
+ return nil, runtime.NewUserFacingError(err.Error())
+ }
return NewUserFillUpComponent(p), nil
})
}
diff --git a/internal/agent/runtime/userfillup.go b/internal/agent/runtime/userfillup.go
new file mode 100644
index 0000000000..b14625569d
--- /dev/null
+++ b/internal/agent/runtime/userfillup.go
@@ -0,0 +1,45 @@
+package runtime
+
+import (
+ "fmt"
+ "strings"
+)
+
+// ValidateUserFillUpOptions checks the form shared by component and interrupt execution.
+func ValidateUserFillUpOptions(params map[string]any, draft bool) error {
+ rawInputs, exists := params["inputs"]
+ if !exists {
+ return nil
+ }
+ inputs, ok := rawInputs.(map[string]any)
+ if !ok {
+ return fmt.Errorf("[UserFillUp] inputs must be an object")
+ }
+ for key, raw := range inputs {
+ entry, ok := raw.(map[string]any)
+ if !ok || entry == nil {
+ return fmt.Errorf("[UserFillUp] inputs.%s must be an object", key)
+ }
+ rawOptions, exists := entry["options"]
+ if !exists {
+ continue
+ }
+ values, ok := rawOptions.([]any)
+ if !ok {
+ return fmt.Errorf("[UserFillUp] inputs.%s.options must be an array", key)
+ }
+ if !draft && hasBlankOption(values) {
+ return fmt.Errorf("[UserFillUp] inputs.%s.options does not support empty entries", key)
+ }
+ }
+ return nil
+}
+
+func hasBlankOption(values []any) bool {
+ for _, value := range values {
+ if s, ok := value.(string); ok && strings.TrimSpace(s) == "" {
+ return true
+ }
+ }
+ return false
+}
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index d3d623b5b7..3728deba24 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -2892,6 +2892,7 @@ Best for: Documents with flowing, contextually connected content — such as boo
'Output the variable content of the upstream component or the text entered by yourself.',
messagePlaceholder: `Please enter your message content, use '/' to quickly insert variables.`,
messageMsg: 'Message cannot be empty',
+ inputOptionsIncomplete: 'Dropdown options cannot contain empty entries',
dataOperationsEntriesIncomplete:
'Complete all data operation entries before running',
invokeVariablesIncomplete:
diff --git a/web/src/pages/agent/utils/canvas-checklist.ts b/web/src/pages/agent/utils/canvas-checklist.ts
index 386b375864..9bca9cf434 100644
--- a/web/src/pages/agent/utils/canvas-checklist.ts
+++ b/web/src/pages/agent/utils/canvas-checklist.ts
@@ -516,6 +516,24 @@ export function collectCanvasIssues({
});
}
+ if (
+ label === Operator.UserFillUp &&
+ Object.values(form?.inputs ?? {}).some(
+ (input: any) =>
+ Array.isArray(input?.options) &&
+ input.options.some(
+ (option: unknown) => typeof option === 'string' && !option.trim(),
+ ),
+ )
+ ) {
+ issues.push({
+ ...target,
+ type: CanvasIssueType.MissingRequired,
+ messageKey: 'flow.inputOptionsIncomplete',
+ blocksRun: true,
+ });
+ }
+
if (label === Operator.DataOperations) {
const blank = (value: unknown) =>
value == null || (typeof value === 'string' && !value.trim());