Table of Contents

Class PatternDetectionAnalyzer

Namespace
AiDotNet.PromptEngineering.Analysis
Assembly
AiDotNet.dll

Analyzer that specializes in detecting prompt patterns and categorizing prompts.

public class PatternDetectionAnalyzer : PromptAnalyzerBase, IPromptAnalyzer
Inheritance
PatternDetectionAnalyzer
Implements
Inherited Members

Remarks

This analyzer identifies what type of prompt is being used and what patterns are present. It can detect few-shot prompts, chain-of-thought patterns, system prompts, and various task types.

For Beginners: Figures out what kind of prompt you're using.

Example:

var analyzer = new PatternDetectionAnalyzer();
var metrics = analyzer.Analyze("Let's think step by step. First, we need to...");

Console.WriteLine(string.Join(", ", metrics.DetectedPatterns));
// Output: "chain-of-thought, instruction"

// This tells you:
// - It's using chain-of-thought reasoning
// - It contains instructions

Common patterns detected:

  • few-shot: Contains examples
  • chain-of-thought: Step-by-step reasoning
  • role-playing: Sets up a persona
  • template: Contains variables
  • question, summarization, translation, etc.

Constructors

PatternDetectionAnalyzer()

Initializes a new instance of the PatternDetectionAnalyzer class.

public PatternDetectionAnalyzer()

Methods

CountExamples(string)

Counts few-shot examples with more sophisticated detection.

protected override int CountExamples(string prompt)

Parameters

prompt string

Returns

int

DetectPatterns(string)

Enhanced pattern detection with more detailed analysis.

protected override IReadOnlyList<string> DetectPatterns(string prompt)

Parameters

prompt string

Returns

IReadOnlyList<string>