promptquality.types.chains package

Submodules

promptquality.types.chains.node_type module

class NodeType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: str, Enum

chain = 'chain'
chat = 'chat'
llm = 'llm'
retriever = 'retriever'
tool = 'tool'
agent = 'agent'

promptquality.types.chains.row module

pydantic model NodeRow

Bases: BaseModel

Chains are constructed of `NodeRow`s. Each NodeRow represents a node in the chain and are modeled as a tree.

Each chain has a root node, which is the first node in the chain. Each non-root node in the chain has a parent node. Parent nodes are necessarily chain nodes.

The required fields for a chain row are node_id, node_type, chain_root_id, and step. The remaining fields are optional and are populated as the chain is executed.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Fields:
field chain_id: Optional[UUID] = None

ID of the parent node of the current node. This maps to parent_run_id from langchain.

Validated by:
  • validate_chain_id

field chain_root_id: UUID [Required]

ID of the root node in the chain.

field creation_timestamp: int [Optional]

Timestamp when the node was created.

field finish_reason: str = ''

Reason for the node’s completion.

field has_children: bool = False

Indicates whether a node has 1 or more child nodes

field inputs: Dict [Optional]

Inputs to the node, as key-value pairs.

field latency: Optional[int] = None

Latency of the node’s execution in nanoseconds.

field node_id: UUID [Required]

ID of that node in the chain. This maps to run_id from langchain.

field node_input: Optional[str] = None

Stringified input to the node in the chain.

field node_name: Optional[str] = None

Name of the node in the chain.

field node_output: Optional[str] = None

Stringified output from the node in the chain.

field node_type: NodeType [Required]

Type of node in the chain.

field params: Dict[str, Any] [Optional]

Parameters passed to the node.

field prompt: Optional[str] = None

Prompt for the node.

field query_input_tokens: int = 0

Number of tokens in the query input.

field query_output_tokens: int = 0

Number of tokens in the query output.

field query_total_tokens: int = 0

Total number of tokens in the query.

field response: Optional[str] = None

Response received after the node’s execution.

field step: int [Required]

Step in the chain. This is always increasing. The root node is step 1, with other nodes incrementing from there.

field target: Optional[str] = None

Target output for a node.

classmethod for_llm(prompt, response, root_id=None, step=1, id=None, name=None)
Return type:

NodeRow

classmethod for_retriever(query, documents, root_id, step=1, id=None, name=None)
Return type:

NodeRow

pydantic model ChainIngestRequest

Bases: BaseModel

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Fields:
field prompt_registered_scorers_configuration: Optional[List[RegisteredScorer]] = None
field prompt_scorers_configuration: Optional[ScorersConfiguration] = None
field rows: List[NodeRow] [Optional]
Validated by:
  • sort_rows

pydantic model ChainIngestResponse

Bases: JobInfoMixin

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Fields:
field message: str [Required]
field num_rows: int [Required]

Module contents