API Reference
This page provides exhaustive, automatically generated technical API reference documentation for the mutant-ai core modules.
Engine
mutant.core.engine
mutant/core/engine.py — V0.5
MutationEngine orchestrates the 6-stage pipeline. Python coordinates; LLMs generate.
V0.5 Changes: - BehaviorProfile is built during analysis and cached on PipelineContext. - Coverage gap detection feeds the planner with structured gap data. - Selective quality review: only ~40% of cases are judged (configurable). - Batch generation: dimensions generate all mutations in one prompt.
Pipeline: analyze_behavior (+ profile cache) → plan_mutations (gap-aware) → generate_mutations (batched) → quality_review (selective) → deduplicate → output
MutationEngine
Orchestrates the V0.4 mutation pipeline.
All generation is delegated to the LLM. Python only coordinates.
Example
engine = MutationEngine(provider=OpenAIProvider()) result = await engine.run(scenario, count=20) print(result.stats) print(result.mutation_plan)
Source code in mutant/core/engine.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
run(scenario, config=None, **kwargs)
async
Run the full 6-stage mutation pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
Scenario
|
|
required |
config
|
MutationConfig | None
|
Configuration object. If provided, overrides kwargs. |
None
|
**kwargs
|
Any
|
Config parameters if config is not provided. |
{}
|
Source code in mutant/core/engine.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
augment(dataset, provider, mutations_per_case=None, quality_review=None, dimensions=None, verbose=None, generate_rationale=None, generate_tags=None, concurrency=3, config=None, **kwargs)
async
Augment an existing dataset by mutating each scenario.
Source code in mutant/core/engine.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
augment_sync(dataset, provider, mutations_per_case=None, quality_review=None, dimensions=None, verbose=None, generate_rationale=None, generate_tags=None, **kwargs)
Synchronous wrapper for dataset augmentation.
Source code in mutant/core/engine.py
mutate(scenario, provider, count=None, quality_review=None, dimensions=None, verbose=None, generate_rationale=None, generate_tags=None, config=None, cache=None, registry=None, **kwargs)
async
Generate LLM-powered behavioral mutations. Primary public API.
Source code in mutant/core/engine.py
mutate_sync(scenario, provider, count=None, quality_review=None, dimensions=None, verbose=None, generate_rationale=None, generate_tags=None, config=None, **kwargs)
Synchronous wrapper for mutate.
Source code in mutant/core/engine.py
Scenarios
mutant.core.scenario
Scenario — the original behavioral situation under test.
Scenario
Bases: BaseModel
Represents a single, original behavioral scenario to be mutated.
A scenario is the atomic unit of input to Mutant. Developers write one realistic scenario; Mutant generates hundreds of behavioral mutations from it.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
str
|
Short human-readable label for the scenario. |
description |
str
|
Full description of the scenario. This is the text that mutations will be applied to. |
context |
dict[str, Any]
|
Optional extra metadata (agent name, domain, tags, etc.). |
tags |
list[str]
|
Free-form labels for filtering / grouping during reporting. |
Examples:
>>> s = Scenario(
... title="Refund Request",
... description="Customer bought a laptop. Requests a refund after 10 days.",
... tags=["customer-support", "refund"],
... )
>>> print(s.title)
'Refund Request'
Source code in mutant/core/scenario.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
from_chat(chat_text, title='Chat Scenario')
classmethod
Create a Scenario directly from raw chat text.
from_dataframe_row(row, text_column='text', title_column=None)
classmethod
Create a Scenario from a Pandas or Polars DataFrame row.
Source code in mutant/core/scenario.py
from_dict(data)
classmethod
Create a Scenario from a dictionary, safely inferring missing fields.
Source code in mutant/core/scenario.py
from_messages(messages, title='Chat Scenario')
classmethod
Create a Scenario from a list of chat messages.
Source code in mutant/core/scenario.py
with_description(description)
Return a shallow copy with a new description (used internally by mutations).
Mutations
mutant.core.mutation
mutant/core/mutation.py — V0.4
All data models for the mutation pipeline. No generation logic lives here.
AugmentedDataset
Bases: BaseModel
Result of augmenting an entire dataset.
Source code in mutant/core/mutation.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
BehaviorAnalysis
Bases: BaseModel
Rich structural analysis of a scenario produced by the LLM.
Source code in mutant/core/mutation.py
DimensionAllocation
Bases: BaseModel
Planner decision for one mutation dimension.
Source code in mutant/core/mutation.py
EvaluationCase
Bases: BaseModel
A single mutation case — rich enough to be used directly in evaluation.
Includes the mutated input, rationale, expected behaviors, and failure modes so it can be plugged directly into any evaluation framework.
Source code in mutant/core/mutation.py
GeneratedMutation
Bases: BaseModel
Raw output from the mutation generation LLM call.
Source code in mutant/core/mutation.py
MutationPlan
Bases: BaseModel
Planner output — exposed in MutationResult for debugging.
Source code in mutant/core/mutation.py
MutationResult
Bases: BaseModel
Complete output of a mutation run.
Source code in mutant/core/mutation.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | |
explain(print_output=True)
Print a structured explanation of the generation process and coverage.
Source code in mutant/core/mutation.py
filter(**kwargs)
Filter cases based on attributes.
Source code in mutant/core/mutation.py
sort_by(field, descending=False)
Sort the cases in this result by a specific field.
Source code in mutant/core/mutation.py
to_csv(path, **kwargs)
Export results to CSV.
Source code in mutant/core/mutation.py
to_dataframe(**kwargs)
Convert results to a pandas DataFrame.
Source code in mutant/core/mutation.py
to_huggingface(**kwargs)
Convert results to a HuggingFace Dataset.
Source code in mutant/core/mutation.py
to_json(path, **kwargs)
Export full result object to JSON.
Source code in mutant/core/mutation.py
to_jsonl(path, **kwargs)
Export cases to a JSON Lines file.
Source code in mutant/core/mutation.py
QualityReviewResult
Bases: BaseModel
Output of the quality review stage.
Source code in mutant/core/mutation.py
QualityScore
Bases: BaseModel
LLM quality verdict for a single mutation case.
Source code in mutant/core/mutation.py
Providers
mutant.providers.base
mutant/providers/base.py
Provider-agnostic LLM abstraction.
No provider-specific code leaks beyond this boundary. The rest of Mutant
only ever sees BaseLLMProvider, LLMMessage, and LLMResponse.
BaseLLMProvider
Bases: ABC
Abstract base class for all LLM providers.
Implementors must only override complete(). JSON extraction and
structured parsing are handled by this base class.
Example
provider = OpenAIProvider(api_key="sk-...") response = await provider.complete([ ... LLMMessage(role="user", content="Hello!") ... ]) print(response.content)
Source code in mutant/providers/base.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
complete(messages, *, temperature=0.8, max_tokens=4096)
abstractmethod
async
Send messages to the provider and return its response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[LLMMessage]
|
Conversation history. Use |
required |
temperature
|
float
|
Sampling temperature (0.0 = deterministic, 1.0 = creative). |
0.8
|
max_tokens
|
int
|
Maximum tokens in the response. |
4096
|
Source code in mutant/providers/base.py
complete_json(messages, schema, *, temperature=0.7, max_tokens=4096, max_retries=3)
async
Complete and parse the response as a Pydantic model.
The default implementation appends a JSON reminder to the last user
message, completes, then extracts and validates JSON. Providers that
natively support structured output (e.g. OpenAI response_format)
can override this for reliability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[LLMMessage]
|
Conversation messages. |
required |
schema
|
type[T]
|
The Pydantic |
required |
Raises:
| Type | Description |
|---|---|
ParseError
|
If the response cannot be parsed as valid JSON or validated
against |
Source code in mutant/providers/base.py
LLMMessage
LLMResponse
Bases: BaseModel
The response from an LLM provider.
Source code in mutant/providers/base.py
ParseError
Bases: Exception
Raised when structured output parsing fails.
Source code in mutant/providers/base.py
ProviderError
Bases: Exception
Raised when an LLM provider returns an error.
Source code in mutant/providers/base.py
mutant.providers.gemini
Gemini provider implementation.
GeminiProvider
Bases: BaseLLMProvider
LLM provider for Google Gemini models.
Requires the gemini extra: pip install mutant-ai[gemini]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Google API key. Defaults to |
None
|
model
|
str
|
Model identifier. Default: |
'gemini-1.5-flash'
|
Source code in mutant/providers/gemini.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
mutant.providers.openai
OpenAI provider implementation.
OpenAIProvider
Bases: BaseLLMProvider
LLM provider for OpenAI (GPT-4o, GPT-4-turbo, o1, etc.).
Requires the openai extra: pip install mutant-ai[openai]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
OpenAI API key. Defaults to |
None
|
model
|
str
|
Model identifier. Default: |
'gpt-4o-mini'
|
base_url
|
str | None
|
Override for OpenAI-compatible endpoints (e.g. Azure, local proxies). |
None
|
default_headers
|
dict[str, str] | None
|
Extra headers to send with every request. |
None
|
Example
provider = OpenAIProvider(model="gpt-4o") cases = await mutate(scenario, provider=provider, count=50)
Source code in mutant/providers/openai.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
complete_json(messages, schema, *, temperature=0.7, max_tokens=4096)
async
Uses OpenAI JSON mode for reliable structured output.
Source code in mutant/providers/openai.py
mutant.providers.anthropic
Anthropic (Claude) provider implementation.
AnthropicProvider
Bases: BaseLLMProvider
LLM provider for Anthropic Claude models.
Requires the anthropic extra: pip install mutant-ai[anthropic]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str | None
|
Anthropic API key. Defaults to |
None
|
model
|
str
|
Model identifier. Default: |
'claude-3-5-haiku-20241022'
|
Example
provider = AnthropicProvider(model="claude-3-5-sonnet-20241022") cases = await mutate(scenario, provider=provider, count=50)
Source code in mutant/providers/anthropic.py
mutant.providers.litellm
LiteLLM provider — unified proxy for 100+ models.
LiteLLMProvider
Bases: BaseLLMProvider
LLM provider that wraps LiteLLM for access to 100+ models.
Requires the litellm extra: pip install mutant-ai[litellm]
LiteLLM supports: OpenAI, Anthropic, Gemini, Azure, Cohere, Mistral, Together, Replicate, and many more — using a unified OpenAI-compatible API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
LiteLLM model string e.g. |
'gpt-4o-mini'
|
api_key
|
str | None
|
API key (if not set via environment). |
None
|
kwargs
|
Any
|
Any additional kwargs passed to |
{}
|
Example
provider = LiteLLMProvider(model="claude-3-5-sonnet-20241022") cases = await mutate(scenario, provider=provider, count=50)
Source code in mutant/providers/litellm.py
Reports
mutant.reports.html
HTML report generator.
HtmlReport
Generates a self-contained HTML report.
Example
report = HtmlReport() report.save(scenario, cases, path="report.html")
Source code in mutant/reports/html.py
mutant.reports.json
JSON and Markdown report generators.
JsonReport
Serialises mutation results to JSON.
Example
report = JsonReport() report.save(scenario, cases, path="report.json")
Source code in mutant/reports/json.py
render(scenario, cases)
save(scenario, cases, path)
Render and save the report to path. Returns the resolved path.
Source code in mutant/reports/json.py
MarkdownReport
Serialises mutation results to a Markdown document.
Example
report = MarkdownReport() report.save(scenario, cases, path="report.md")
Source code in mutant/reports/json.py
save(scenario, cases, path)
Render and save the report to path. Returns the resolved path.