Skip to content

attest.code_review

Code review mode, importable as from attest.code_review import ....

Inputs

ReviewOutput pydantic-model

Bases: BaseModel

Fields:

output_type pydantic-field

output_type: OutputType

text pydantic-field

text: str

diffs pydantic-field

diffs: dict[str, str]

changed_files pydantic-field

changed_files: list[str] | None = None

reads pydantic-field

reads: list[FileRead]

question pydantic-field

question: str | None = None

group_name pydantic-field

group_name: str | None = None

paths

paths() -> list[str]

FileRead pydantic-model

Bases: BaseModel

Fields:

tool pydantic-field

tool: Literal['read_file', 'grep'] = 'read_file'

arguments pydantic-field

arguments: JsonObject

output pydantic-field

output: str

PullRequest pydantic-model

Bases: BaseModel

Fields:

diffs pydantic-field

diffs: dict[str, str]

changed_files pydantic-field

changed_files: list[str]

title pydantic-field

title: str = ''

description pydantic-field

description: str = ''

commit_messages pydantic-field

commit_messages: list[str]

Building runs

to_run

to_run(
    output: ReviewOutput,
    *,
    limits: EvidenceLimits | None = None,
    guidelines: ReviewGuidelines | None = None,
) -> Trajectory

Build the run for a review output; evidence comes only from tool calls.

to_run_with_omissions

to_run_with_omissions(
    output: ReviewOutput,
    *,
    limits: EvidenceLimits | None = None,
    guidelines: ReviewGuidelines | None = None,
) -> RunWithOmissions

Build the run for a review output and list which files had content left out and why.

guidelines, when given, are added as a read_guidelines step so claims citing a rule can be checked.

EvidenceLimits pydantic-model

Bases: BaseModel

How many characters of diff one file, and one whole run, may put into evidence.

Config:

  • frozen: True

Fields:

model_config class-attribute instance-attribute

model_config = ConfigDict(frozen=True)

max_file_chars pydantic-field

max_file_chars: int = 12000

max_run_chars pydantic-field

max_run_chars: int = 60000

Omission pydantic-model

Bases: BaseModel

A file whose diff was summarized, cut or left out of the evidence, and why.

Config:

  • frozen: True

Fields:

model_config class-attribute instance-attribute

model_config = ConfigDict(frozen=True)

path pydantic-field

path: str

reason pydantic-field

reason: OmissionReason

changed_lines pydantic-field

changed_lines: int = 0

omitted_hunks pydantic-field

omitted_hunks: int = 0

detect_answer_kind

detect_answer_kind(traj: Trajectory) -> KindDetection

Pick "code" or "factual" from the run's tool calls. Makes no model calls.

Reviewing a pull request

review

review(
    pr: PullRequest,
    outputs: Sequence[ReviewOutput] | None = None,
    *,
    evaluate: Evaluator,
    guidelines: GuidelinesInput = None,
    follow_guidelines: bool = True,
    modes: Mapping[str, GateMode] | None = None,
    deep: bool = True,
    limits: EvidenceLimits | None = None,
) -> ReviewResult

Scan the pull request for injection once, then grade and gate each output on its evidence.

With no outputs, attest writes the review itself, following guidelines. guidelines are the team's review rules (markdown paths or text). They are evidence, so an issue citing one can be checked, and follow_guidelines drops outputs that break one. Without them, attest's own reviewer follows the built-in general standard, and outputs are checked for faithfulness only. Outputs without their own diffs or changed-file list use the pull request's. evaluate turns a run into a Report with a faithfulness result, and modes overrides the default gate mode per output type.

ReviewResult pydantic-model

Bases: BaseModel

Fields:

decisions pydantic-field

decisions: list[OutputDecision]

injection pydantic-field

injection: CheckResult

guidelines pydantic-field

guidelines: ReviewGuidelines | None = None

written pydantic-field

written: bool = False

warnings pydantic-field

warnings: list[str]

outputs pydantic-field

outputs: list[ReviewOutput]

kept property

kept: list[int]

dropped property

dropped: list[int]

filter

filter(
    outputs: Sequence[ReviewOutput] | None = None,
) -> list[ReviewOutput]

Return the outputs this review kept, in their original order.

OutputDecision pydantic-model

Bases: BaseModel

Fields:

index pydantic-field

index: int

output_type pydantic-field

output_type: OutputType

text pydantic-field

text: str = ''

question pydantic-field

question: str | None = None

paths pydantic-field

paths: list[str]

keep pydantic-field

keep: bool

mode pydantic-field

mode: GateMode

score pydantic-field

score: float | None = None

summary pydantic-field

summary: str = ''

reasons pydantic-field

reasons: list[Finding]

notes pydantic-field

notes: list[Finding]

omissions pydantic-field

omissions: list[Omission]

write_review

write_review(
    pr: PullRequest,
    *,
    guidelines: GuidelinesInput = None,
    limits: EvidenceLimits | None = None,
) -> list[ReviewOutput]

Review a pull request: issues, one summary per changed file, and an overview.

Guidelines

load_guidelines

load_guidelines(
    value: GuidelinesInput = None,
) -> ReviewGuidelines

Resolve guidelines from a path, markdown text, a list of paths, or None for the default.

ReviewGuidelines pydantic-model

Bases: BaseModel

Fields:

name pydantic-field

name: str

rules pydantic-field

rules: list[Guideline]

builtin pydantic-field

builtin: bool = False

get

get(rule_id: str) -> Guideline | None

render

render() -> str

The rules as numbered lines, grouped under their section.

Guideline pydantic-model

Bases: BaseModel

Fields:

id pydantic-field

id: str

text pydantic-field

text: str

section pydantic-field

section: str = ''

source pydantic-field

source: str = ''

Checking and gating

check_code_injection

check_code_injection(
    pr: PullRequest,
    outputs: list[ReviewOutput] | None = None,
    *,
    deep: bool = True,
    budget_chars: int = 8000,
) -> CheckResult

Scan a pull request for text planted to steer an automated reviewer.

gate

gate(
    report: Report,
    output_type: OutputType | str,
    *,
    mode: GateMode | str | None = None,
    injection: CheckResult | None = None,
    paths: list[str] | None = None,
    output_index: int | None = None,
) -> GateDecision

Decide whether to keep one review output.

reasons lists the findings that drop it. notes lists findings shown beside it that do not. Findings against the built-in general standard are always notes; only your own rules drop. A claim no verifier judged (a failed or skipped call) drops the output in every mode.

GateDecision pydantic-model

Bases: BaseModel

Fields:

keep pydantic-field

keep: bool

mode pydantic-field

mode: GateMode

reasons pydantic-field

reasons: list[Finding]

notes pydantic-field

notes: list[Finding]