Prompt Template Variable Hydrator
When formatting prompts dynamically, you substitute variables into a template. To keep templates clean, they contain placeholders formatted like {variable_name}.
Tasks
Implement the function hydrate_prompt(template, variables, defaults) to:
- Substitute all placeholders matching
{variable_name}with their values from thevariablesanddefaultsdictionaries. - If a placeholder required by the template is missing from both dictionaries, raise a
KeyErrorwith the missing key name. - Ensure that if
defaultsis not provided, it defaults to an empty dictionary.