fail and Custom Validation Guards
Stopping rendering with clear, actionable errors.
fail and Custom Validation Guards is a free Helm Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Helm Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Guarding Bad Input
Charts should reject nonsensical configuration early. A good template can stop rendering and tell the user exactly what went wrong.
Stopping with fail
The fail function halts template rendering immediately and prints the message you give it as the error.
{{ fail "service.port must be set" }}Guarding with an if
Wrap fail in an if so it only triggers when a value is missing or invalid, leaving valid installs untouched.
{{ if not .Values.image }}{{ fail "image is required" }}{{ end }}required for Single Values
For one mandatory value, required is simpler: it returns the value or fails with your message when it is empty.
{{ required "image.tag is required" .Values.image.tag }}fail vs required
Use required to demand a single value inline, and fail when your check spans several conditions or needs custom logic.
Validating an Enum
You can guard that a value is one of an allowed set, failing clearly when a user picks something unsupported.
{{ if not (has .Values.tier (list "free" "pro")) }}{{ fail "tier must be free or pro" }}{{ end }}Helpful Messages
Write the failure message as advice: name the value and the fix, so the user is not left guessing why the install stopped.
Checking Combinations
Some rules involve two fields. A guard can fail when an enabled feature lacks the companion value it depends on.
{{ if and .Values.tls.enabled (not .Values.tls.secret) }}{{ fail "tls.secret needed when tls.enabled" }}{{ end }}Centralize Your Guards
Putting validation in a named template in _helpers.tpl keeps checks in one place and out of every resource file.
{{- include "mychart.validate" . -}}Test the Guards
Run helm template with bad values to confirm each guard fires with a clear message before anything reaches the cluster.
Schema Checks Too
For type and range rules, a values.schema.json file complements fail by rejecting bad input before any template even runs.
Quick Check
Quick check on validation helpers.
Recap
You learned to stop bad installs early: fail for custom multi-condition guards and required for mandatory single values. 🎉
Frequently asked questions
Is the “fail and Custom Validation Guards” lesson free?
Yes — the full text of “fail and Custom Validation Guards” is free to read here on the web, and the Helm Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Helm Academy course, upgrade to CoddyKit PRO.
What will I learn in “fail and Custom Validation Guards”?
Stopping rendering with clear, actionable errors. You practise Helm Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Helm Academy?
No prior experience is required. Helm Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “fail and Custom Validation Guards” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Helm Academy lesson?
Yes. Every Helm Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Deep Merge with mergeOverwrite and dict
- tpl: Rendering Strings from Values
- Looping Files with range Over .Files.Glob
- fail and Custom Validation Guards