PromptSpec#

class rapidtools.gui.PromptSpec(asset: str = 'building', imagery: str = 'aerial', objective: str = '', persona: str = '', focus: str = '', marking: str = '', steps: list[str] = <factory>, edge_cases: list[str] = <factory>, fields: list[OutputField] = <factory>, rubric_title: str = '', rubric_field: str = '', rubric: list[RubricEntry] = <factory>, context: str = '', json_output: bool = False)[source]#

Bases: object

Everything needed to assemble a prompt in the rapidtools sample layout.

Variables:
  • asset (str) – What is being analysed ('building', 'vehicle').

  • imagery (str) – 'aerial', 'street' or 'multi-temporal street'.

  • objective (str) – What the model must do, phrased after “Analyze each provided image and …” ('assign a CHS Level (0-4) to the primary building structure').

  • persona (str) – Expertise the model should adopt.

  • focus (str) – Scope statements such as what to ignore.

  • marking (str) – How the asset is marked on the crop, from describe_marking().

  • steps (list[str]) – Numbered analysis steps; generated when empty.

  • edge_cases (list[str]) – Sentences describing alternative classifications.

  • fields (list[OutputField]) – The output fields, in order.

  • rubric_title (str) – Heading of the class descriptions block.

  • rubric_field (str) – Name of the field the rubric explains; defaults to the first categorical field.

  • rubric (list[RubricEntry]) – One RubricEntry per class.

  • context (str) – Optional background paragraph appended at the end.

  • json_output (bool) – Ask for a JSON object instead of Key: value lines.

Example

>>> spec = PromptSpec.from_dict({'asset': 'road', 'fields': [
...     {'name': 'Blocked', 'kind': 'boolean'}]})
>>> spec.fields[0].format_line()
'Blocked: [true or false]'

Methods

attribute_keys

Attribute names the analyzer will write for this prompt.

default_steps

Analysis steps used when the user has not written any.

from_dict

Build a spec from a JSON object, ignoring unknown keys.

primary_field

The field the rubric describes.

to_dict

Serialise to plain JSON-compatible data.

classmethod from_dict(data: dict[str, Any] | None) → PromptSpec[source]#

Build a spec from a JSON object, ignoring unknown keys.

Parameters:

data (dict[str, Any] | None) – Keys matching the attributes; nested fields and rubric entries may be dicts.

Returns:

PromptSpec – The coerced specification.

Raises:

ValueError – If data is not an object or a field kind is invalid.

to_dict() → dict[str, Any][source]#

Serialise to plain JSON-compatible data.

primary_field() → OutputField | None[source]#

The field the rubric describes.

Returns:

OutputField | None – The field named by rubric_field if it exists, else the first categorical field, else None.

attribute_keys(prefix: str = '') → list[str][source]#

Attribute names the analyzer will write for this prompt.

Parameters:

prefix (str) – The backend’s attribute prefix ('gemini').

Returns:

list[str] – '<prefix>_<key>' per field ('<key>' without a prefix).

default_steps() → list[str][source]#

Analysis steps used when the user has not written any.