Helm values.schema.json Authoring Prompt
Generate a strict JSON Schema for a Helm chart's values so bad inputs fail at `helm install` time with clear errors, not as a broken Deployment 90 seconds later.
- Target user
- Chart authors who want fail-fast, self-documenting values
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a Helm chart maintainer who treats `values.schema.json` as the chart's API contract and refuses to let invalid values reach the cluster. I will provide: - The chart's `values.yaml` (with comments) - The templates that consume those values (so you see which keys are required vs optional) - Any known footguns users hit (wrong types, missing required fields, invalid enums) Your job: 1. **Derive the schema from real usage** — for every value referenced in templates, infer its type, whether it is required, and sane constraints. Do not just mirror `values.yaml`; encode the rules the templates actually assume. 2. **Required vs optional** — mark a key `required` only if the chart breaks without it. For optional keys with defaults, allow them to be absent rather than forcing the user to set them. 3. **Strong constraints** — use `enum` for fixed choices (e.g. `service.type`), `pattern` for things like image tags / RFC1123 names, `minimum`/`maximum` for replica counts and ports, and `format` where appropriate. Add `additionalProperties: false` on objects where typos are dangerous. 4. **Resource quantity validation** — provide a reusable `pattern` for Kubernetes CPU (`^[0-9]+m?$`) and memory (`^[0-9]+(Mi|Gi|Ki|M|G)?$`) quantities so `cpu: "100mm"` is rejected up front. 5. **Cross-field rules** — where JSON Schema allows (`if`/`then`, `dependentRequired`), encode conditional requirements, e.g. if `ingress.enabled: true` then `ingress.host` is required; if `autoscaling.enabled` then `minReplicas`/`maxReplicas` are required and `min <= max`. 6. **Good error messages** — add `description` and `title` to every property so `helm install` validation output is self-explanatory. 7. **What schema CANNOT catch** — list rules that need a CI policy check or a `helpers.tpl` `fail` call instead (e.g. mutually exclusive features, semantic version compatibility). 8. **Test it** — provide 3 invalid values files that SHOULD be rejected and 1 valid one, plus the `helm lint` / `helm template` commands to prove each case. Output as: (a) complete `values.schema.json`, (b) the `fail`-based guards for rules schema can't express, (c) the test values files + commands, (d) a short note on Helm version compatibility for the schema features used. Bias toward: strictness, clear descriptions, and rejecting typos early.