Extract JSON from llm response
Function: Extract JSON from AI Response
This action helps you automatically find and extract structured data (JSON) from a text response generated by an Artificial Intelligence (AI) model. AI models often provide information in natural language, but sometimes you need specific data in a structured format to use in other parts of your application. This action intelligently searches the AI's text for JSON and makes it available for you to use.
Input,
- LLM Response: A piece of text. This is the full response you received from an AI model. This input is required.
Output,
- Result: A piece of text. This is the extracted JSON content found within the AI's response. By default, this will be stored in a variable named
RESULT, but you can choose a different variable name if needed.
Execution Flow,
Real-Life Examples,
Here are some examples of how you can use the "Extract JSON from AI Response" action:
-
Extracting User Profile Data:
- Scenario: You ask an AI to generate a new user profile based on some inputs, and the AI responds with a mix of natural language and structured data.
- Inputs:
- LLM Response: "Here is the new user profile you requested:
json\{\"username\": \"jane.doe\", \"email\": \"[email protected]\", \"status\": \"active\"\}. Please confirm this is correct."
- LLM Response: "Here is the new user profile you requested:
- Result: The variable
RESULTwill contain the text\{"username": "jane.doe", "email": "[email protected]", "status": "active"\}. You can then use this structured data to create a new user record in your database.
-
Parsing a List of Product Recommendations:
- Scenario: You ask an AI to recommend products based on a customer's preferences, and the AI provides a list of products in a JSON array.
- Inputs:
- LLM Response: "Based on your preferences, I recommend the following products: [{"id": 101, "name": "Wireless Headphones", "price": 99.99}, {"id": 102, "name": "Smartwatch", "price": 149.99}]. Let me know if you'd like more details."
- Result: The variable
RESULTwill contain the text[\{"id": 101, "name": "Wireless Headphones", "price": 99.99\}, \{"id": 102, "name": "Smartwatch", "price": 149.99\}]. This list can then be displayed to the user or used to update a product catalog.
-
Retrieving Configuration Settings:
- Scenario: An AI provides configuration settings for a new feature, embedded within a longer explanation.
- Inputs:
- LLM Response: "To enable the new analytics dashboard, please use the following settings: {"dashboard_enabled": true, "data_source": "google_analytics", "refresh_interval_minutes": 60}. This will ensure all data is up-to-date."
- Result: The variable
RESULTwill contain the text\{"dashboard_enabled": true, "data_source": "google_analytics", "refresh_interval_minutes": 60\}. These settings can then be applied to configure the new feature in your application.