IPromptAnalyzer
Interfaces · AiDotNet.Interfaces
Defines the contract for analyzing prompts before sending them to language models.
Known implementations: PromptAnalyzerBase
For Beginners
A prompt analyzer is like a spell-checker and cost calculator for your prompts.
Before sending a prompt to an AI model (which costs money), the analyzer tells you:
- How many tokens it uses (tokens = cost)
- Estimated API cost in dollars
- How complex the prompt is
- Any potential problems (missing variables, too long, etc.)
Example workflow:
Benefits:
- Cost control: Know costs before making API calls
- Optimization: Find prompts that are too long or complex
- Debugging: Catch issues before they cause errors
- Budgeting: Track and forecast API spending
How It Works
A prompt analyzer computes metrics and validates prompts to help developers understand and optimize their prompts before incurring API costs. Analysis includes token counting, cost estimation, complexity measurement, and issue detection.
Properties
| Property | Summary |
|---|---|
string Name { get; } |
Gets the name of this analyzer implementation. |
Methods
| Method | Summary |
|---|---|
IEnumerable<PromptIssue> ValidatePrompt(string prompt, ValidationOptions options) |
Validates a prompt for potential issues. |
PromptMetrics Analyze(string prompt) |
Analyzes a prompt and returns detailed metrics. |
Task<PromptMetrics> AnalyzeAsync(string prompt, CancellationToken cancellationToken) |
Analyzes a prompt asynchronously for use in async workflows. |