Ask AI
Skip to main content

Extract XML from llm response

Function: Extract XML from LLM Response

This action helps you automatically find and pull out XML text from a longer response generated by an AI (Large Language Model). This is useful when an AI provides information embedded within a larger message, and you only need the structured XML part.

Input

  • LLM Response (Text): The full text response from your AI model that you expect to contain XML. This input is required.

Output

  • result (Text): The extracted XML text. If the action successfully finds XML, it will store it in a variable named "RESULT" by default, or any other name you specify. If no XML is found, this variable will not be updated by this action.

Execution Flow

Real-Life Examples

Here are some practical examples of how you can use the "Extract XML from LLM Response" action:

Example 1: AI Provides Pure XML Configuration

Scenario: You ask an AI to generate a configuration file in XML format, and its response is solely the XML content.

  • Inputs:
    • LLM Response:
      <configuration>
      <setting name="theme" value="dark"/>
      <setting name="notifications" value="enabled"/>
      </configuration>
  • Result: The variable RESULT will contain:
    <configuration>
    <setting name="theme" value="dark"/>
    <setting name="notifications" value="enabled"/>
    </configuration>

Example 2: AI Provides XML Embedded in a Conversational Message

Scenario: You ask an AI for a product description, and it provides some introductory text followed by the product details in an XML block.

  • Inputs:
    • LLM Response:

      "Here is the product information you requested:

      ```xml
      <product>
      <id>P123</id>
      <name>Wireless Earbuds</name>
      <price currency="USD">99.99</price>
      <features>
      <feature>Noise Cancelling</feature>
      <feature>Bluetooth 5.0</feature>
      </features>
      </product>

      Let me know if you need anything else!"

  • Result: The variable RESULT will contain:
    <product>
    <id>P123</id>
    <name>Wireless Earbuds</name>
    <price currency="USD">99.99</price>
    <features>
    <feature>Noise Cancelling</feature>
    <feature>Bluetooth 5.0</feature>
    </features>
    </product>

Example 3: AI Provides Text Without Recognizable XML

Scenario: You ask an AI a question, and its response is plain text without any XML structure or XML code blocks.

  • Inputs:
    • LLM Response:
      "The capital of France is Paris. It is known for its art, fashion, gastronomy, and culture."
  • Result: The variable RESULT will not be updated by this action, as no XML was found. You might want to add a check in your workflow to see if RESULT is empty after this action to handle cases where no XML is extracted.