# schema

URL: /milo-cli/api/milo/schema/
Section: milo
Description: Function signature → JSON Schema for MCP tool compatibility.

---

> For a complete page index, fetch /milo-cli/llms.txt.

Open LLM text
(/milo-cli/api/milo/schema/index.txt)

Share with AI

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

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fschema%2Findex.txt)

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

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

Module

#
`schema`

Function signature → JSON Schema for MCP tool compatibility.

8Classes9Functions

## Classes

`MinLen`

1

▼

Minimum length for strings (minLength) or items for arrays (minItems).

Minimum length for strings (minLength) or items for arrays (minItems).

#### Attributes

Name
Type
Description

`value`

`int`

—

`MaxLen`

1

▼

Maximum length for strings (maxLength) or items for arrays (maxItems).

Maximum length for strings (maxLength) or items for arrays (maxItems).

#### Attributes

Name
Type
Description

`value`

`int`

—

`Gt`

1

▼

Exclusive minimum constraint for numbers.

Exclusive minimum constraint for numbers.

#### Attributes

Name
Type
Description

`value`

`int | float`

—

`Lt`

1

▼

Exclusive maximum constraint for numbers.

Exclusive maximum constraint for numbers.

#### Attributes

Name
Type
Description

`value`

`int | float`

—

`Ge`

1

▼

Inclusive minimum constraint for numbers.

Inclusive minimum constraint for numbers.

#### Attributes

Name
Type
Description

`value`

`int | float`

—

`Le`

1

▼

Inclusive maximum constraint for numbers.

Inclusive maximum constraint for numbers.

#### Attributes

Name
Type
Description

`value`

`int | float`

—

`Pattern`

1

▼

Regex pattern constraint for strings.

Regex pattern constraint for strings.

#### Attributes

Name
Type
Description

`value`

`str`

—

`Description`

1

▼

Override or supplement the parameter description.

Override or supplement the parameter description.

#### Attributes

Name
Type
Description

`value`

`str`

—

## Functions

`function_to_schema`

3

`dict[str, Any]`

▼

Generate MCP-compatible JSON Schema from function type annotations.

Parameters…

`def function_to_schema(func: Callable[..., Any], *, strict: bool = False, warn_missing_docs: bool = False) -> dict[str, Any]`

Generate MCP-compatible JSON Schema from function type annotations.

Parameters with defaults are optional (not in required).
X | None unions unwrapped to base type.
Supports: str, int, float, bool, list[X], dict[str, X], X | None,
Enum, Literal, dataclass, TypedDict, Union.

Parameter descriptions are extracted from the function's docstring
(Google, NumPy, or Sphinx style) and included as`"description"`
fields in the schema properties.

`Context`-typed parameters (and any parameter named `ctx`) are
intentionally omitted from the returned schema. The CLI dispatcher
injects them at call time, so they are invisible to MCP clients and
should not appear in`tools/list`descriptors. See
`_is_context_type`() for the exact detection rules.

When strict is True, unrecognized type annotations raise
`TypeError` instead of silently falling back to `"string"`.

When warn_missing_docs is True, every schema parameter without a
description (no`Args:` entry and no `Annotated[..., Description(...)]`)
emits a`UserWarning`. Default `False`so production schema
generation stays silent;`milo verify`opts in.

##### Parameters

Name
Type
Description

`func`
`Callable[..., Any]`

`strict`
`bool`

Default:`False`

`warn_missing_docs`
`bool`

Default:`False`

##### Returns

`dict[str, Any]`

`_function_to_schema_cached`

2

`tuple[dict[str, Any], tu…`

▼

Compute (schema, undocumented_param_names). Cached; warnings live in the wrappe…

`def _function_to_schema_cached(func: Callable[..., Any], *, strict: bool = False) -> tuple[dict[str, Any], tuple[str, ...]]`

Compute (schema, undocumented_param_names). Cached; warnings live in the wrapper.

##### Parameters

Name
Type
Description

`func`
`Callable[..., Any]`

`strict`
`bool`

Default:`False`

##### Returns

`tuple[dict[str, Any], tuple[str, ...]]`

`_type_to_schema`

4

`dict[str, Any]`

▼

Convert Python type annotation to JSON Schema fragment.

*_defs* accumulates ``…

`def _type_to_schema(annotation: Any, _seen: set[int] | None = None, _defs: dict[str, dict[str, Any]] | None = None, *, _strict: bool = False) -> dict[str, Any]`

Convert Python type annotation to JSON Schema fragment.

_defs accumulates`$defs`entries for recursive dataclasses so
they can be emitted as`{"$ref": "#/$defs/ClassName"}`.

When _strict is True, unrecognized types raise TypeError.

##### Parameters

Name
Type
Description

`annotation`
`Any`

`_seen`
`set[int] | None`

Default:`None`

`_defs`
`dict[str, dict[str, Any]] | None`

Default:`None`

`_strict`
`bool`

Default:`False`

##### Returns

`dict[str, Any]`

`_is_typed_dict`

1

`bool`

▼

Check if annotation is a TypedDict subclass.

`def _is_typed_dict(annotation: Any) -> bool`

##### Parameters

Name
Type
Description

`annotation`
`Any`

##### Returns

`bool`

`_is_optional`

1

`bool`

▼

Check if annotation is X | None.

`def _is_optional(annotation: Any) -> bool`

##### Parameters

Name
Type
Description

`annotation`
`Any`

##### Returns

`bool`

`_unwrap_optional`

1

`Any`

▼

Extract non-None type from X | None.

`def _unwrap_optional(annotation: Any) -> Any`

##### Parameters

Name
Type
Description

`annotation`
`Any`

##### Returns

`Any`

`return_to_schema`

1

`dict[str, Any] | None`

▼

Generate JSON Schema from function return type annotation.

Returns None if the…

`def return_to_schema(func: Callable[..., Any]) -> dict[str, Any] | None`

Generate JSON Schema from function return type annotation.

Returns None if the function has no return annotation or returns None.

##### Parameters

Name
Type
Description

`func`
`Callable[..., Any]`

##### Returns

`dict[str, Any] | None`

`_is_context_type`

2

`bool`

▼

Check if an annotation refers to milo's Context type.

`def _is_context_type(annotation: Any, name: str) -> bool`

##### Parameters

Name
Type
Description

`annotation`
`Any`

`name`
`str`

##### Returns

`bool`

`_parse_param_docs`

1

`dict[str, str]`

▼

Extract parameter descriptions from a docstring.

Supports Google, Sphinx, and …

`def _parse_param_docs(docstring: str) -> dict[str, str]`

Extract parameter descriptions from a docstring.

Supports Google, Sphinx, and NumPy docstring styles::

```
# Google style
```

##### Parameters

Name
Type
Description

`docstring`
`str`

##### Returns

`dict[str, str]`
