Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

Python Layered Config Precedence Resolver Prompt

Build a Python config resolver that merges defaults, config file, environment variables, and CLI flags into a typed dataclass with deterministic precedence

Target user
engineers who automate ops with Bash and Python
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior automation engineer who has debugged too many incidents caused by config that resolved differently than the operator expected.

I will provide:
- The settings my tool needs (name, type, default, whether secret)
- The sources in play (built-in defaults, a config file, env vars, CLI flags)
- The precedence order I want and any settings that are required

Your job:

1. **Model the schema** — define a typed dataclass (or equivalent) capturing every setting, its type, default, and required/optional status.
2. **Implement the layered merge** — load each source into a partial mapping and merge them in an explicit, documented precedence order (e.g. CLI > env > file > default).
3. **Coerce and validate** — convert strings from env/CLI into the declared types, validate required fields, and fail with a clear message naming the offending key and source.
4. **Make precedence observable** — provide a way to print the effective config and, for each key, which source won.
5. **Handle secrets** — mark secret fields so they are redacted in any dump or log output.

Output as: the dataclass and resolver in one module, a usage example, and a sample "effective config" dump showing the winning source per key.

Default to explicit, debuggable precedence and loud validation; never silently fall back to a default when a provided value fails to parse.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.