What does the Prompt Variable Extractor do?
The Prompt Variable Extractor automatically parses AI prompts, system instructions, and LLM prompt templates to detect, isolate, and index all dynamic variable placeholders. It supports Mustache / Handlebars / Jinja ({{var}}), Template Literals (${var}), Python f-strings & LangChain ({var}), XML Tags & Angle Brackets (<var>), Windows Environment (%var%), and SQL Named Parameters (:var), instantly generating JSON schemas, mock test dictionaries, and LangChain input arrays.
Core Concepts
Understanding prompt variables in modern AI workflows:
- Zero-Friction Template Migration: Different prompt management tools and orchestrators use varying delimiter standards. This extractor identifies all variations in a single pass.
- Automated JSON Schema Generation: LangChain, Semantic Kernel, and OpenAI Structured Outputs require strict parameter schema definitions. The extractor compiles detected variables into Draft 2020-12 JSON Schema objects ready for API integration.
- Duplicate & Position Tracking: Reports both unique variable lists and exact line/column coordinates for every placeholder reference across your prompt.
- WebMCP Integration: Enables autonomous AI coding assistants, agent browser extensions, and local LLMs to query prompt schemas via local Model Context Protocol (MCP) tool calls.
How to use the tool?
- Enter Prompt or Template: Paste your AI prompt into the editor, click Upload, or click Sample.
- Filter by Syntax Pattern: Select All Syntaxes or narrow down to a specific format like
{{var}},${var}, or{var}. - Choose Output Generator View: Switch between Variable Breakdown Table, JSON Schema, Mock JSON Payload, or LangChain Python Snippet.
- Copy or Export: Click Copy Variables to copy the selected format or Download JSON to export the structured schema report.
Context-Aware Practical Workflow Guides
IDE Shortcuts & LLM Orchestration
- VS Code: Use
Ctrl+F(Cmd+Fon macOS) with regex\{\{([^}]+)\}\}to quickly highlight Handlebars variables in prompt files. - LangChain / LangSmith: Export the generated
PromptTemplate(input_variables=[...])snippet directly into your Python backend codebase.
Related Developer Utilities
- AI Token Counter: Calculate token counts, subword metrics, and prompt costs across leading AI models.
- AI Text Chunker: Partition large documents and prompt inputs into model-friendly context chunks.
- JSON Formatter: Format and validate JSON schemas for LLM tool calling.
- YAML to JSON Converter: Convert YAML prompt templates into JSON manifests.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/ai/extract-prompt-variables) for programmatic variable extraction.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | The prompt string or template to analyze. | "Hello {{user_name}}, welcome to ${company}." |
syntax |
String | Optional syntax filter (default: "all"). |
"double_braces" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/ai/extract-prompt-variables \
-H "Content-Type: application/json" \
-d '{
"rawText": "Explain the architectural setup for {{project_type}} using ${framework} with <security_level>."
}'Python
import requests
url = "https://blueutils.com/api/ai/extract-prompt-variables"
payload = {
"rawText": "Explain the architectural setup for {{project_type}} using ${framework}."
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "Explain the architectural setup for {{project_type}} using ${framework}."
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/ai/extract-prompt-variables"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether extraction succeeded. | true |
variables |
Array | Array of extracted variable metadata objects. | [{ "name": "project_type", "occurrences": 1 }] |
uniqueCount |
Number | Count of distinct variable names. | 2 |
totalOccurrences |
Number | Total references across prompt. | 3 |
jsonSchema |
Object | Draft 2020-12 JSON Schema object for tool calling. | { "type": "object", "properties": ... } |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"uniqueCount": 2,
"totalOccurrences": 2,
"varNames": ["framework", "project_type"],
"variables": [
{
"name": "framework",
"rawMatches": ["${framework}"],
"syntaxTypes": ["dollar_braces"],
"occurrences": 1,
"positions": [{ "line": 1, "column": 52 }]
},
{
"name": "project_type",
"rawMatches": ["{{project_type}}"],
"syntaxTypes": ["double_braces"],
"occurrences": 1,
"positions": [{ "line": 1, "column": 30 }]
}
],
"jsonSchema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"framework": { "type": "string", "description": "Value for template parameter \"framework\"" },
"project_type": { "type": "string", "description": "Value for template parameter \"project_type\"" }
},
"required": ["framework", "project_type"]
},
"sampleJson": {
"framework": "<framework_value>",
"project_type": "<project_type_value>"
}
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid input: Prompt payload cannot be empty."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to extract prompt variables?
- Dynamic Template Validation: Automatically inspect and validate user-submitted prompt templates in CI/CD pipelines before deployment to production agents.
- Automated Tool Calling & Schema Generation: Generate OpenAI and Anthropic tool call input schemas dynamically at runtime without manually coding repetitive boilerplate.
- Multi-Tenant Prompt Management: Index variable keys across thousands of organization prompts for search, audit, and variable auto-completion.
Native Usage
How to extract prompt variables locally in terminal environments:
Windows (PowerShell)
# Extract {{variable}} and ${variable} in PowerShell
$prompt = Get-Content -Raw -Path "prompt.txt"
[regex]::Matches($prompt, '\{\{\s*([^}]+)\s*\}|\$\{\s*([^}]+)\s*\}') | ForEach-Object { $_.Value }Linux / Unix (Bash)
# Extract {{variable}} matches using grep
grep -oP '\{\{\s*\K[a-zA-Z_0-9\-]+(?=\s*\}\})' prompt.txt | sort -uPython
Using Python standard library:
import re
prompt = "Hello {{user_name}}, welcome to ${company}! Your role is {role}."
pattern = r'\{\{\s*([a-zA-Z0-9_-]+)\s*\}\}|\$\{\s*([a-zA-Z0-9_-]+)\s*\}|(?<!\{)\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}(?!\})'
matches = re.findall(pattern, prompt)
variables = sorted(list(set(filter(None, [var for match in matches for var in match]))))
print("Extracted Variables:", variables)Java
Using Java standard library:
import java.util.*;
import java.util.regex.*;
public class PromptExtractor {
public static void main(String[] args) {
String prompt = "Hello {{user_name}}, welcome to ${company}!";
Pattern pattern = Pattern.compile("\\{\\{\\s*([a-zA-Z0-9_-]+)\\s*\\}\\}|\\$\\{\\s*([a-zA-Z0-9_-]+)\\s*\\}");
Matcher matcher = pattern.matcher(prompt);
Set<String> variables = new TreeSet<>();
while (matcher.find()) {
String v = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
variables.add(v);
}
System.out.println("Variables: " + variables);
}
}