Code Toolbox
Extract code
Extract just the code from a string, removing anything extra like comments or other text.
This is handy when cleaning up code generated by an LLM or pulling out code from mixed content like scripts or web scraping results.
Parameters
- None - The string data should be provided as chained input to this function.
Returns
- Description - A brief summary of the extracted code.
- Type - The programming language of the code.
- Code - The cleaned and extracted code.
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:
Clean HTML
Extract just the HTML from a string, removing anything extra like comments or other text.
This is handy when cleaning up HTML generated by an LLM or pulling out HTML from mixed content like web scraping results.
Parameters
- CSS Selectors - The CSS selectors array to remove from the HTML.
Returns
- HTML Code - The cleaned and extracted HTML.
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
Extract just the SQL code from a string, creating a formatted version of the query if enabled.
This feature is useful for formatting and securing SQL code from LLM-generated responses, tailored to different SQL server types.
Parameters
- Reformat - When set to "true", the SQL code is reformatted for readability. Default "false".
- Only Select statements - When set to "true", only SELECT statements are extracted. Default is "true".
- Database Type - Specifies the type of database (e.g., "PostgresQL", "MySQL", "BigQuery") for compatibility during SQL extraction and cleaning.
Returns
- Code - The extracted and formatted SQL code.
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: