Composable Assertions
Combine assertions with logical operators.
all_of — AND
expect.all_of(
expect.contains("Paris"),
expect.not_contains("London"),
expect.latency_under(2000),
)any_of — OR
expect.any_of(
expect.contains("capital"),
expect.contains("city"),
)custom
expect.custom(lambda output: len(output.content.split()) < 50)Operators
Use & for AND and | for OR:
@llm_test(
expect.contains("Paris") & expect.not_contains("London"),
expect.contains("capital") | expect.contains("city"),
model="gpt-4o-mini",
)
def test_composable(llm):
llm("What is the capital of France?")Nesting
expect.all_of(
expect.is_not_empty(),
expect.any_of(
expect.contains("Paris"),
expect.contains("paris"),
),
expect.latency_under(3000),
)& is shorthand for all_of, | is shorthand for any_of. Use whichever reads better in your tests.
Last updated on