Starts With

Checks whether the agent output begins with a specified prefix string. Supports case-insensitive matching and optional whitespace trimming.

Config

FieldTypeRequiredDefaultDescription
valuestringYesThe prefix string to check for
case_sensitivebooleanNofalseEnable case-sensitive matching
trimbooleanNotrueTrim whitespace from both output and prefix before checking

Use Cases

  • Format enforcement — Ensure agent responses start with a required prefix such as "Answer:", "Summary:", or a JSON opening brace.
  • Greeting validation — Verify that customer-facing agents always begin with an appropriate greeting like "Hello" or "Thank you for contacting us".
  • Structured output checks — Confirm that outputs begin with expected markers like { for JSON or < for XML/HTML.
  • Protocol compliance — Assert that API-facing agents produce responses starting with a specific status prefix or identifier.

Examples

Require a prefix

// Pass if output starts with "Answer:"
{
  "value": "Answer:"
}
// Output: "Answer: The capital of France is Paris." → pass
// Output: "The capital of France is Paris." → fail

Case-sensitive prefix

// Require exact casing
{
  "value": "ERROR:",
  "case_sensitive": true
}
// Output: "ERROR: Connection failed" → pass
// Output: "error: Connection failed" → fail

JSON output detection

// Check that output begins with a JSON object
{
  "value": "{"
}
// Output: '{"result": "success"}' → pass
// Output: "The result is success" → fail

Scoring

Returns 1.0 (pass) or 0.0 (fail). No intermediate scores. Returns 0.0 if no value is provided in the config.

Performance

Starts With performs a simple prefix check with no external API calls. Execution time is under 1ms regardless of output length, making it ideal for high-volume evaluation pipelines.

Have questions? Join our community!

Connect with other developers and the 2Signal team.

Join Discord