code: def self_correcting_pipeline():
      # Create the RAG pipeline
      rag_pipeline = Pipeline(max_loops_allowed=10)
      rag_pipeline.add_component(
          instance=Multiplexer(str), name="query_multiplexer"
      )
      rag_pipeline.add_component(
          instance=PaginatedRetriever(
              InMemoryBM25Retriever(
                  document_store=InMemoryDocumentStore()
              )
          ),
          name="retriever",
      )
      rag_pipeline.add_component(
          instance=PromptBuilder(
              template="""
      Given these documents, answer the question.
      If the documents don't provide enough information to answer the question, answer with the string "UNKNOWN".
  
      Documents:
      {% for doc in documents %}
          {{ doc.content }}
      {% endfor %}
  
      Question: {{question}}
      Answer:
      """
          ),
          name="prompt_builder",
      )
      rag_pipeline.add_component(instance=OpenAIGenerator(), name="llm")
      rag_pipeline.add_component(
          instance=ConditionalRouter(
              routes=[
                  {
                      "condition": "{{ 'UNKNOWN' in replies|join(' ') }}",
                      "output": "{{ query }}",
                      "output_name": "unanswered_query",
                      "output_type": str,
                  },
                  {
                      "condition": "{{ 'UNKNOWN' not in replies|join(' ') }}",
                      "output": "{{ replies }}",
                      "output_name": "replies",
                      "output_type": List[str],
                  },
              ]
          ),
          name="answer_checker",
      )
  
      rag_pipeline.connect("query_multiplexer", "retriever")
      rag_pipeline.connect(
          "query_multiplexer", "prompt_builder.question"
      )
      rag_pipeline.connect("query_multiplexer", "answer_checker.query")
      rag_pipeline.connect("retriever", "prompt_builder.documents")
      rag_pipeline.connect("prompt_builder", "llm")
      rag_pipeline.connect("llm.replies", "answer_checker.replies")
      rag_pipeline.connect(
          "answer_checker.unanswered_query", "query_multiplexer"
      )
  
      # Draw the pipeline
      rag_pipeline.draw("self_correcting_pipeline.png")
  
      # Populate the document store
      documents = [
          Document(content="My name is Jean and I live in Paris."),
          Document(content="My name is Mark and I live in Berlin."),
          Document(content="My name is Giorgio and I live in Rome."),
          Document(content="My name is Juan and I live in Madrid."),
      ]
      rag_pipeline.get_component(
          "retriever"
      ).retriever.document_store.write_documents(documents)
  
      # Query and assert
      question = "Who lives in Germany?"
  
      result = rag_pipeline.run(
          {"query_multiplexer": {"value": question}}
      )
  
      pprint(result)
  
file_path: haystack/examples/rag/rag_self_correction.py
imports: from typing import List, Any, Optional, Dict
  import logging
  from pprint import pprint
  from haystack import Pipeline, Document, component, default_to_dict, default_from_dict, DeserializationError
  from haystack.document_stores.in_memory import InMemoryDocumentStore
  from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
  from haystack.components.generators import OpenAIGenerator
  from haystack.components.builders.prompt_builder import PromptBuilder
  from haystack.components.others import Multiplexer
  from haystack.components.routers.conditional_router import ConditionalRouter
  from haystack.core.component.types import Variadic
label_desc: Use image node_id 1 for calling a global function with example usage: self_correcting_pipeline() without return types