Validation Functions
Validation functions in Mule ensure that AI-generated code meets quality standards before being committed. These functions act as automated quality gates, running tests, linters, and other checks on the code.
Built-in Validation Functions
Mule includes several built-in validation functions for Go codebases:
getDeps
func getDeps(path string) (string, error)
This function ensures all dependencies are installed by running make download-golangci-lint
. It’s typically the first validation function to run to ensure other tools are available.
goFmt
func goFmt(path string) (string, error)
Formats Go code according to standard conventions by running go fmt ./...
. This ensures consistent code formatting throughout the codebase.
goModTidy
func goModTidy(path string) (string, error)
Cleans up Go module dependencies by running go mod tidy
. This ensures that all imports are properly declared in the go.mod file and removes unused dependencies.
golangciLint
func golangciLint(path string) (string, error)
Runs a comprehensive set of linters via make lint
to catch common coding issues, potential bugs, and style violations.
goTest
func goTest(path string) (string, error)
Executes tests with go test ./...
to verify that the code functions as expected and doesn’t break existing functionality.
How Validation Works
When an agent generates code changes, Mule runs the specified validation functions in sequence:
- The agent makes code changes to the repository
- Each validation function is executed in the order specified
- If any validation fails, the output is captured and sent back to the agent
- The agent attempts to fix the issues based on the validation output
- This process repeats until all validations pass or the maximum retry limit is reached
Configuring Validations
Validation functions can be configured at the workflow level:
validationFunctions:
- getDeps
- goFmt
- goModTidy
- golangciLint
- goTest
For specific agents, you can configure different validation sets based on the task requirements.
Creating Custom Validation Functions
You can extend Mule with custom validation functions for your specific needs:
Define your validation function with the signature:
func YourValidator(path string) (string, error)
Register it in the validation function map:
var functions = map[string]ValidationFunc{ // existing functions... "yourValidator": YourValidator, }
Add it to your workflow configuration
Language-specific Validations
While the built-in validators focus on Go, you can create custom validators for other languages:
JavaScript/TypeScript Example
func eslint(path string) (string, error) {
cmd := exec.Command("npx", "eslint", ".")
cmd.Dir = path
out, err := cmd.CombinedOutput()
return string(out), err
}
func jest(path string) (string, error) {
cmd := exec.Command("npx", "jest")
cmd.Dir = path
out, err := cmd.CombinedOutput()
return string(out), err
}
Python Example
func pylint(path string) (string, error) {
cmd := exec.Command("python", "-m", "pylint", ".")
cmd.Dir = path
out, err := cmd.CombinedOutput()
return string(out), err
}
func pytest(path string) (string, error) {
cmd := exec.Command("python", "-m", "pytest")
cmd.Dir = path
out, err := cmd.CombinedOutput()
return string(out), err
}
Handling Validation Failures
When validation fails, Mule follows a structured approach:
- The validation error output is captured
- The agent is provided with:
- The specific validation that failed
- The error output from the validation
- The original code changes
- The agent is asked to fix the issues
- The process is repeated up to 20 times (configurable)
Best Practices
To get the most out of validation functions:
- Start simple: Begin with basic formatting and linting before adding comprehensive tests
- Clear error messages: Ensure your custom validators provide clear, actionable error messages
- Fast feedback: Optimize validation functions to run quickly for better agent iteration
- Progressive validation: Order validations from fastest to slowest for efficiency
- Context-aware validation: Include repository-specific checks that enforce your project’s conventions
Debugging Validation Issues
If validation consistently fails:
- Run the validation commands manually to see the output
- Check if validation requirements are clearly communicated in the agent’s prompt
- Verify that validation tools are properly installed and configured
- Consider relaxing validation requirements for initial development phases