PromptAssert
NexusLabs.Needlr.AgentFramework.Testing¶
PromptAssert Class¶
Assertion helpers for verifying prompt integrity without LLM invocation. Use in unit tests to catch prompt regressions (missing safety rules, deleted sections, forbidden patterns) at zero token cost.
Inheritance System.Object 🡒 PromptAssert
Example¶
[Fact]
public void WriterPrompt_HasSafetyRules()
{
PromptAssert.Contains(WriterPrompt.Text, "ABSOLUTE RULE");
PromptAssert.ContainsInSection(WriterPrompt.Text, "### Critical", "meta-instruction-leak");
PromptAssert.ForbidsPattern(WriterPrompt.Text, @"TODO|FIXME|HACK");
}
Methods¶
PromptAssert.Contains(string, string) Method¶
Asserts that prompt contains expected using System.StringComparison.OrdinalIgnoreCase.
Parameters¶
prompt System.String
The prompt text to inspect.
expected System.String
The substring that must be present.
Exceptions¶
System.ArgumentException
prompt is null or
expected is null or empty.
PromptAssertionException
The expected text was not found.
PromptAssert.Contains(string, string, StringComparison) Method¶
Asserts that prompt contains expected using the specified comparison.
Parameters¶
prompt System.String
The prompt text to inspect.
expected System.String
The substring that must be present.
comparison System.StringComparison
The comparison rule to use.
Exceptions¶
System.ArgumentException
prompt is null or
expected is null or empty.
PromptAssertionException
The expected text was not found.
PromptAssert.ContainsInSection(string, string, string) Method¶
Asserts that expected appears within the markdown section that starts at sectionHeader. The section ends at the next header of equal or higher level, or at the end of the prompt.
Parameters¶
prompt System.String
The prompt text to inspect.
sectionHeader System.String
The markdown header that starts the section (e.g., "### Critical").
expected System.String
The text that must appear inside the section.
Exceptions¶
System.ArgumentException
prompt is null or
sectionHeader or expected is null or empty.
PromptAssertionException
The section was not found, or the expected text was not in the section.
PromptAssert.DoesNotContain(string, string) Method¶
Asserts that prompt does NOT contain forbidden using System.StringComparison.OrdinalIgnoreCase.
Parameters¶
prompt System.String
The prompt text to inspect.
forbidden System.String
The substring that must be absent.
Exceptions¶
System.ArgumentException
prompt is null or
forbidden is null or empty.
PromptAssertionException
The forbidden text was found.
PromptAssert.ForbidsPattern(string, string) Method¶
Asserts that prompt does not match regexPattern.
Parameters¶
prompt System.String
The prompt text to inspect.
regexPattern System.String
A regular expression pattern that must NOT match.
Exceptions¶
System.ArgumentException
prompt is null or
regexPattern is null or empty.
PromptAssertionException
The pattern matched.
PromptAssert.HasSection(string, string) Method¶
Asserts that prompt contains a markdown section header
matching sectionHeader (e.g., "### Critical").
Parameters¶
prompt System.String
The prompt text to inspect.
sectionHeader System.String
The markdown header text (including # prefix).
Exceptions¶
System.ArgumentException
prompt is null or
sectionHeader is null or empty.
PromptAssertionException
The section header was not found.
PromptAssert.SectionOrder(string, string, string) Method¶
Asserts that firstSection appears before secondSection in prompt.
Parameters¶
prompt System.String
The prompt text to inspect.
firstSection System.String
The section header that should come first.
secondSection System.String
The section header that should come second.
Exceptions¶
System.ArgumentException
prompt is null or
firstSection or secondSection is null or empty.
PromptAssertionException
A section was not found, or the order was reversed.