Skip to content

Code Toolbox

Extract Code

Extract code from markdown.

{{ extractCode }}
Example Usage

Here’s how to extract Python code from a LLM output:

{{ LLM  | prompt: "Create a Python script to iterate over an array of 3 different fruits and print their name and characters size" | cache: "true" }}
{{ extractCode  }}=>{{ variable  | name: "extractedCode" }}
<< name: extractedCode, prompt: false >>

The result will be the extracted code. In this case it would be Python:

# Define an array of fruits
fruits = ["apple", "banana", "cherry"]
# Iterate over the array
for fruit in fruits:
    # Get the length of the fruit name
    length = len(fruit)
    # Print the fruit name and its character size
    print(f"Fruit: {fruit}, Characters: {length}")


Clean HTML

Cleanse HTML.

Parameters

  • selectors: An array of CSS selectors to remove from the HTML
{{ cleanHTML }}
Example Usage

Here’s how to convert extract HTML code from a LLM output:

<html>
<head>
    <title>Sample HTML</title>
</head>
<body>
    <div class="header">
        <h1>Welcome to the Sample Page</h1>
    </div>
    <div class="content">
        <p>This is a sample paragraph with some <span class="highlight">highlighted text</span>.</p>
        <p>Another paragraph with <a href="https://example.com">a link</a>.</p>
    </div>
    <div class="footer">
        <p>Footer content here.</p>
    </div>
</body>
</html>
{{ cleanHTML  | selectors: "['.footer']" }}=>{{ variable  | name: "cleanedHTML" }}
<< name: cleanedHTML, prompt: false >>

The result will be the extracted HTML:

<html>
<head>
    <title>Sample HTML</title>
</head>
<body>
    <div class="header">
        <h1>Welcome to the Sample Page</h1>
    </div>
    <div class="content">
        <p>This is a sample paragraph with some <span class="highlight">highlighted text</span>.</p>
        <p>Another paragraph with <a href="https://example.com">a link</a>.</p>
    </div>
</body>
</html>


Clean SQL

Cleanse SQL.

Parameters

  • reformat: Parse and reformat the SQL

  • onlySelect: Only allow select statements

  • dbType: The type of database

{{ cleanSQL  | reformat: "true" | onlySelect: "false" | dbType: "PostgresQL" }}
Example Usage

Here’s how to clean SQL:

{{ LLM  | prompt: "Generate a SELECT query to count and group students by course enrollment using the students, courses, and enrollments tables. Return SQL code only, without any explanations." | cache: "true" }}
{{ cleanSQL  | reformat: "true" | onlySelect: "true" | dbType: "PostgresQL" }}=>{{ variable  | name: "cleanedSQL" }}
<< name: cleanedSQL, prompt: false >>

The result will be the extracted and formatted SQL:

SELECT "c".course_name, COUNT("e".student_id) AS "student_count" FROM "courses" AS "c" INNER JOIN "enrollments" AS "e" ON "c".course_id = "e".course_id GROUP BY "c".course_name