Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Langgenius Dify InputValidation

From Leeroopedia
Revision as of 17:55, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Langgenius_Dify_InputValidation.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources Dify
Domains Frontend, Validation
Last Updated 2026-02-12 07:00 GMT

Overview

Dify's frontend input validation patterns enforce correctness for LLM completion parameters and template variable definitions, catching invalid configurations before they reach the backend.

Description

The completion parameter validation module (utils/completion-params.ts) implements mergeValidCompletionParams, which reconciles existing model parameters against a set of ModelParameterRule definitions. For each parameter, the function validates the value type (int, float, boolean, string, tag) against the corresponding rule, checks numeric ranges (min/max bounds), and validates string options against allowed value lists. Parameters that fail validation are removed and tracked in a removedDetails record with explanatory reasons (e.g., "unsupported", "invalid type", "out of range"). The function also handles special cases like preserving stop sequences in advanced mode regardless of rule presence.

The template variable validation module (utils/var.ts) provides checkKey and checkKeys functions that enforce naming conventions for prompt template variables. Keys must match the pattern /^\w+$/ (alphanumeric and underscore only), must not start with a digit, and must not exceed MAX_VAR_KEY_LENGTH. The getVars function extracts template variables from prompt strings using the Template:Variable name syntax, filtering out system placeholders ({{#context#}}, {{#histories#}}, {{#query#}}, {{#pre_prompt#}}) and deduplicating results.

Together, these validation layers ensure that user-configured model parameters stay within provider-defined bounds and that prompt template variables follow consistent naming rules. Both modules return structured error information (typed error message keys for i18n or detailed removal reasons) rather than throwing exceptions, enabling the UI to present specific, actionable feedback.

Usage

Use this principle when:

  • Adding new model parameter types or validation rules to the completion configuration
  • Implementing variable extraction or validation for new prompt template formats
  • Building form validation for any user-configurable LLM settings

Theoretical Basis

These validation patterns implement Schema Validation at the presentation layer, where parameter rules serve as a runtime schema that incoming values are validated against. The approach follows the Fail Fast principle by catching invalid configurations in the client before they are submitted, reducing round-trip error cycles. The structured error reporting aligns with Contextual Error Messaging practices that provide users with specific guidance on how to fix invalid inputs.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment