class_docstr: DynamicPromptBuilder is designed to construct dynamic prompts for the pipeline. Users can change the prompt
  template at runtime by providing a new template for each pipeline run invocation if needed.
  
  The following example demonstrates how to use the DynamicPromptBuilder:
  
  ```python
  from typing import List
  from haystack.components.builders import DynamicPromptBuilder
  from haystack.components.generators import OpenAIGenerator
  from haystack import Pipeline, component, Document
  
  prompt_builder = DynamicPromptBuilder(runtime_variables=["documents"])
  llm = OpenAIGenerator(api_key="<your-api-key>", model="gpt-3.5-turbo")
  
  
  @component
  class DocumentProducer:
  
      @component.output_types(documents=List[Document])
      def run(self, doc_input: str):
          return {"documents": [Document(content=doc_input)]}
  
  
  pipe = Pipeline()
  pipe.add_component("doc_producer", DocumentProducer())
  pipe.add_component("prompt_builder", prompt_builder)
  pipe.add_component("llm", llm)
  pipe.connect("doc_producer.documents", "prompt_builder.documents")
  pipe.connect("prompt_builder.prompt", "llm.prompt")
  
  template = "Here is the document: {{documents[0].content}} \n Answer: {{query}}"
  result = pipe.run(
      data={
          "doc_producer": {"doc_input": "Hello world, I live in Berlin"},
          "prompt_builder": {
              "prompt_source": template,
              "template_variables": {"query": "Where does the speaker live?"},
          },
      }
  )
  print(result)
  
  >> {'llm': {'replies': ['The speaker lives in Berlin.'],
  >> 'meta': [{'model': 'gpt-3.5-turbo-0613',
  >> 'index': 0,
  >> 'finish_reason': 'stop',
  >> 'usage': {'prompt_tokens': 28,
  >> 'completion_tokens': 6,
  >> 'total_tokens': 34}}]}}
  
  Note how in the example above, we can dynamically change the prompt template by providing a new template to the
  run method of the pipeline. This dynamic prompt generation is in stark contrast to the static prompt generation
  using `PromptBuilder`, where the prompt template is fixed for the pipeline's lifetime and cannot be changed
  for each pipeline run invocation.
docstr: Checks if all the required template variables are provided to the pipeline `run` method.
  If all the required template variables are provided, returns a Jinja2 template object.
  Otherwise, raises a ValueError.
  
  :param template_text: A Jinja2 template as a string.
  :param provided_variables: A set of provided template variables.
  :type provided_variables: Set[str]
  :return: A Jinja2 template object if all the required template variables are provided.
  :raises ValueError: If all the required template variables are not provided.
docstr_tok: ["Checks","if","all","the","required","template","variables","are","provided","to","the","pipeline","`","run","`","method",".","If","all","the","required","template","variables","are","provided",",","returns","a","Jinja2","template","object",".","Otherwise",",","raises","a","ValueError",".",":","param","template_text",":","A","Jinja2","template","as","a","string",".",":","param","provided_variables",":","A","set","of","provided","template","variables",".",":","type","provided_variables",":","Set","[","str","]",":","return",":","A","Jinja2","template","object","if","all","the","required","template","variables","are","provided",".",":","raises","ValueError",":","If","all","the","required","template","variables","are","not","provided","."]
code: def _validate_template(
      self, template_text: str, provided_variables: Set[str]
  ):
      """
      Checks if all the required template variables are provided to the pipeline `run` method.
      If all the required template variables are provided, returns a Jinja2 template object.
      Otherwise, raises a ValueError.
  
      :param template_text: A Jinja2 template as a string.
      :param provided_variables: A set of provided template variables.
      :type provided_variables: Set[str]
      :return: A Jinja2 template object if all the required template variables are provided.
      :raises ValueError: If all the required template variables are not provided.
      """
      template = Template(template_text)
      ast = template.environment.parse(template_text)
      required_template_variables = meta.find_undeclared_variables(ast)
      filled_template_vars = required_template_variables.intersection(
          provided_variables
      )
      if len(filled_template_vars) != len(required_template_variables):
          raise ValueError(
              f"The {self.__class__.__name__} requires specific template variables that are missing. "
              f"Required variables: {required_template_variables}. Only the following variables were "
              f"provided: {provided_variables}. Please provide all the required template variables."
          )
      return template
  
imports: import logging
  from typing import Dict, Any, Optional, List, Set
  from jinja2 import Template, meta
  from haystack import component
label_desc: Use image node_id 3 for calling the DynamicPromptBuilder obj's underlying member method code with example usage: obj._validate_template(template_text, provided_variables) and returns: template