# context_contracts

URL: /kida/api/analysis/context_contracts/
Section: analysis
Description: Route-agnostic context contract checks for compiled templates.

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/analysis/context_contracts/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fanalysis%2Fcontext_contracts%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fanalysis%2Fcontext_contracts%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fanalysis%2Fcontext_contracts%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fanalysis%2Fcontext_contracts%2Findex.txt)

Module

#
`analysis.context_contracts`

Route-agnostic context contract checks for compiled templates.

2Classes3Functions

## Classes

`SupportsContextAnalysis`

4

▼

Minimal template protocol needed by context contract checks.

Minimal template protocol needed by context contract checks.

#### Attributes

Name
Type
Description

`name`

`str | None`

—

#### Methods

`depends_on`

0

`frozenset[str]`

▼

`def depends_on(self) -> frozenset[str]`

##### Returns

`frozenset[str]`

`list_defs`

0

`list[str]`

▼

`def list_defs(self) -> list[str]`

##### Returns

`list[str]`

`list_blocks`

0

`list[str]`

▼

`def list_blocks(self) -> list[str]`

##### Returns

`list[str]`

`ContextContractIssue`

8

▼

Machine-readable context contract finding.

Machine-readable context contract finding.

#### Attributes

Name
Type
Description

`code`

`Literal['K-CTX-001', 'K-CTX-002']`

—

`severity`

`Literal['error', 'warning']`

—

`path`

`str`

—

`message`

`str`

—

`template_name`

`str | None`

—

`lineno`

`int | None`

—

`col_offset`

`int | None`

—

`suggestion`

`str | None`

—

## Functions

`_flatten_mapping`

2

`set[str]`

▼

Return dotted paths available from a nested mapping contract.

`def _flatten_mapping(mapping: Mapping[str, Any], prefix: str = '') -> set[str]`

##### Parameters

Name
Type
Description

`mapping`
`Mapping[str, Any]`

`prefix`
`str`

Default:`''`

##### Returns

`set[str]`

`_normalize_paths`

1

`set[str]`

▼

Normalize context contract input into dotted paths.

`def _normalize_paths(paths_or_mapping: Iterable[str] | Mapping[str, Any] | None) -> set[str]`

##### Parameters

Name
Type
Description

`paths_or_mapping`
`Iterable[str] | Mapping[str, Any] | None`

##### Returns

`set[str]`

`check_context_contract`

5

`list[ContextContractIssu…`

▼

Compare template dependencies against a provided context contract.

``provided`…

`def check_context_contract(template: SupportsContextAnalysis, provided: Iterable[str] | Mapping[str, Any], *, optional: Iterable[str] | Mapping[str, Any] | None = None, globals: Iterable[str] | Mapping[str, Any] | None = None, check_extra: bool = False) -> list[ContextContractIssue]`

Compare template dependencies against a provided context contract.

`provided` is route/framework data. `globals`are values guaranteed by
the environment or adapter. Both accept dotted-path iterables or nested
mappings. Top-level keys do not satisfy dotted paths unless the exact dotted
path is present; use`template.validate_context()`for legacy top-level
checks.

##### Parameters

Name
Type
Description

`template`
`SupportsContextAnalysis`

`provided`
`Iterable[str] | Mapping[str, Any]`

`optional`
`Iterable[str] | Mapping[str, Any] | None`

Default:`None`

`globals`
`Iterable[str] | Mapping[str, Any] | None`

Default:`None`

`check_extra`
`bool`

Default:`False`

##### Returns

`list[ContextContractIssue]`
