Skip to navigation

Field

View as MarkdownOpen in Claude

Field declares one thing an operation or a lookup takes from the caller. Declare it as a class attribute on an Operation subclass; the attribute name is the tool argument’s name. Field is a frozen dataclass.

A field whose value is missing, None, an empty string, or the text "not said" (the NOT_SAID constant, any case) counts as not given: values.<name> is None.

from signalwire.operations import Field

Parameters

kind
AnyRequired

The value’s type: str, int, float, bool, a Literal, list[...], dict[str, ...], a TypedDict, or a JSON schema dict. Any other type raises TypeError when the schema is built.

description
strRequired

What it is, in the caller’s terms. The model reads it.

required
boolDefaults to True

Whether the operation needs it.

ask
str | NoneDefaults to None

The question for the caller when it’s missing. With ask, a required field the model sends empty, null, or as "not said" is asked for before prepare() runs, so the model isn’t pushed to invent a value. A field with a fixed choice of values gets "not said" as an extra option.

Methods

schema() returns the field’s JSON schema, with its description.

Example

from typing import Literal
from signalwire.operations import Field
order_id = Field(str, "The order to cancel.")
reason = Field(
Literal["no longer needed", "ordered by mistake"],
"Why they're cancelling.",
ask="Why are they cancelling it?",
)
print(reason.schema())