This pull request introduces a new attribute, expected_template_data_keys, to the PromptPart class. This attribute ensures that specific keys are present in the template data when rendering a prompt. The changes enhance the integrity of template data and prevent runtime errors due to missing keys.
Changes
New Attribute in PromptPart:
expected_template_data_keys: A list of keys expected to be present in the template data.
Validation Method:
Added _validate_template_replacements method in the Prompt class to check for the presence of required keys in template_data.
This method is invoked in the _render_parts method for each PromptPart instance.
Refactoring:
Updated _render_parts method to include the validation step.
Minor refactoring for code readability and maintenance.
Rationale
The addition of expected_template_data_keys helps ensure that all necessary data is available in the template context, reducing the likelihood of runtime errors caused by missing template data. This makes the code more robust and easier to debug.
Testing
Tested the new attribute by creating PromptPart instances with and without expected_template_data_keys.
Validated that the _validate_template_replacements method correctly identifies missing keys and raises appropriate errors.
Ensured existing functionality remains unaffected by the new changes.
Related Issues
This change addresses issues related to template data integrity and aims to prevent errors that occur due to missing keys in the template data.
Overview
This pull request introduces a new attribute,
expected_template_data_keys
, to thePromptPart
class. This attribute ensures that specific keys are present in the template data when rendering a prompt. The changes enhance the integrity of template data and prevent runtime errors due to missing keys.Changes
New Attribute in PromptPart:
expected_template_data_keys
: A list of keys expected to be present in the template data.Validation Method:
_validate_template_replacements
method in thePrompt
class to check for the presence of required keys intemplate_data
._render_parts
method for eachPromptPart
instance.Refactoring:
_render_parts
method to include the validation step.Rationale
The addition of
expected_template_data_keys
helps ensure that all necessary data is available in the template context, reducing the likelihood of runtime errors caused by missing template data. This makes the code more robust and easier to debug.Testing
PromptPart
instances with and withoutexpected_template_data_keys
._validate_template_replacements
method correctly identifies missing keys and raises appropriate errors.Related Issues
This change addresses issues related to template data integrity and aims to prevent errors that occur due to missing keys in the template data.
Thank you!