PtcRunner.Schema (PtcRunner v0.9.0)

Copy Markdown View Source

Declarative schema module that defines all DSL operations.

This module serves as the single source of truth for operation definitions, supporting validation, JSON Schema generation, and documentation.

Summary

Functions

Get operation definition by name.

Returns all operation definitions.

Generate a JSON Schema (draft-07) for the PTC DSL.

Generate a flattened JSON Schema optimized for LLM structured output.

Generate a concise prompt describing PTC operations for LLM text mode.

Returns a sorted list of valid operation names.

Functions

get_operation(operation_name)

@spec get_operation(String.t()) :: {:ok, map()} | :error

Get operation definition by name.

Arguments

  • operation_name: The name of the operation

Returns

  • {:ok, definition} if the operation exists
  • :error if the operation is unknown

operations()

@spec operations() :: map()

Returns all operation definitions.

Returns

A map where keys are operation names and values are operation definitions.

to_json_schema()

@spec to_json_schema() :: map()

Generate a JSON Schema (draft-07) for the PTC DSL.

Returns

A map representing the JSON Schema that can be encoded to JSON.

to_llm_schema()

@spec to_llm_schema() :: map()

Generate a flattened JSON Schema optimized for LLM structured output.

This schema uses anyOf to list all operations at the top level, avoiding the recursive $ref patterns that LLMs struggle with. The schema is designed to work with ReqLLM.generate_object! for structured output mode.

Returns

A map representing the flattened JSON Schema for the PTC DSL.

to_prompt(opts \\ [])

@spec to_prompt(keyword()) :: String.t()

Generate a concise prompt describing PTC operations for LLM text mode.

This produces a human-readable description of operations suitable for system prompts. Includes operation reference, memory contract, key rules, and examples.

Options

  • :examples - number of full JSON examples to include (default: 3)

Returns

A string containing operation descriptions and examples.

valid_operation_names()

@spec valid_operation_names() :: [String.t()]

Returns a sorted list of valid operation names.

Returns

A list of operation names in sorted order.