Component. This enables integration of new features, data manipulation, external services, and specialized tools.
In LLM Controls’ node-based environment, each node is a “component” that performs discrete functions. Custom components are Python classes which define:
- Inputs — Data or parameters your component requires.
- Outputs — Data your component provides to downstream nodes.
- Logic — How you process inputs to produce outputs.
- The Python class that inherits from
Component. - Class-level attributes that identify and describe the component.
- Input and output lists that determine data flow.
- Internal variables for logging and advanced logic.
Class-level attributes
Define these attributes to control a custom component’s appearance and behavior:- display_name: A user-friendly label in the node header.
- description: A brief summary shown in tooltips.
- icon: A visual identifier from LLM Controls’ icon library.
- name: A unique internal identifier.
- documentation: An optional link to external docs.
Structure of a custom component
A LLM Controls custom component goes beyond a simple class with inputs and outputs. It includes an internal structure with optional lifecycle steps, output generation, front-end interaction, and logic organization. A basic component:- Inherits from
llmc.custom.Component. - Declares metadata like
display_name,description,icon, and more. - Defines
inputsandoutputslists. - Implements methods matching output specifications.
Internal Lifecycle and Execution Flow
LLM Controls’ engine manages:- Instantiation: A component is created, and internal structures are initialized.
- Assigning Inputs: Values from the UI or connections are assigned to component fields.
- Validation and Setup: Optional hooks like
_pre_run_setup. - Outputs Generation:
run()orbuild_results()triggers output methods.
initialize_dataor_pre_run_setupcan run setup logic before the component’s main execution.__call__,run(), or_run()can be overridden to customize how the component is called or to define custom execution logic.
Inputs and outputs
Custom component inputs are defined with properties like:name,display_name- Optional:
info,value,advanced,is_list,tool_mode,real_time_refresh
StrInput: simple text input.DropdownInput: selectable options.HandleInput: specialized connections.
Output properties define:
name,display_name,method- Optional:
info
Associated Methods
Each output is linked to a method:- The output method name must match the method name.
- The method typically returns objects like Message, Data, or DataFrame.
- The method can use inputs with
self.<input_name>.
Components with multiple outputs
A component can define multiple outputs. Each output can have a different corresponding method. For example:Common internal patterns
_pre_run_setup()
To initialize a custom component with counters set:
Override runor _run
You can override async def _run(self): ... to define custom execution logic, although the default behavior from the base class usually covers most cases.
Store data in self.ctx
Use self.ctx as a shared storage for data or counters across the component’s execution flow:
Directory structure requirements
By default, LLM Controls looks for custom components in thellmc/components directory.
If you’re creating custom components in a different location using the LLM Controls COMPONENTS PATH environment variable, components must be organized in a specific directory structure to be properly loaded and displayed in the UI:
Components must be placed inside category folders, not directly in the base directory. The category folder name determines where the component appears in the UI menu.
For example, to add a component to the Helpers menu, place it in a helpers subfolder:
You can have multiple category folders to organize components into different menus:
This folder structure is required for LLM Controls to properly discover and load your custom components. Components placed directly in the base directory will not be loaded.
Custom component inputs and outputs
Inputs and outputs define how data flows through the component, how it appears in the UI, and how connections to other components are validated.Inputs
Inputs are defined in a class-levelinputs list. When LLM Controls loads the component, it uses this list to render fields and ports in the UI. Users or other components provide values or connections to fill these inputs.
An input is usually an instance of a class from llmc.io (such as StrInput, DataInput, or MessageTextInput). The most common constructor parameters are:
name: The internal variable name, accessed viaself.<name>.display_name: The label shown to users in the UI.info(optional): A tooltip or short description.value(optional): The default value.advanced(optional): IfTrue, moves the field into the “Advanced” section.required(optional): IfTrue, forces the user to provide a value.is_list(optional): IfTrue, allows multiple values.input_types(optional): Restricts allowed connection types (e.g.,["Data"],["LanguageModel"]).
StrInputcreates a single-line text field.MultilineInputcreates a multi-line text area.
BoolInput,IntInput, andFloatInputprovide fields for boolean, integer, and float values, ensuring type consistency.
DropdownInput
SecretStrInputfor API keys and passwords.
DataInputexpects aDataobject (typically with.dataand optional.text).MessageInputexpects aMessageobject, used in chat or agent-based flows.MessageTextInputsimplifies access to the.textfield of aMessage.
HandleInput
FileInput
is_list=True to accept multiple values, ideal for batch or grouped operations.
This example defines three inputs: a text field (StrInput), a boolean toggle (BoolInput), and a dropdown selection (DropdownInput).
Outputs
Outputs are defined in a class-leveloutputs list. When LLM Controls renders a component, each output becomes a connector point in the UI. When you connect something to an output, LLM Controls automatically calls the corresponding method and passes the returned object to the next component.
An output is usually an instance of Output from llmc.io, with common parameters:
name: The internal variable name.display_name: The label shown in the UI.method: The name of the method called to produce the output.info(optional): Help text shown on hover.
self.status message inside the method to show progress or logs.
Common Return Types:
Message: Structured chat messages.Data: Flexible object with.dataand optional.text.DataFrame: Pandas-based tables (llmc.schema.DataFrame).- Primitive types:
str,int,bool(not recommended if you need type/color consistency).
DataToDataFrame component defines its output using the outputs list. The df_out output is linked to the build_df method, so when connected in the UI, LLM Controls calls this method and passes its returned DataFrame to the next node. This demonstrates how each output maps to a method that generates the actual output data.
Tool mode
You can configure a Custom Component to work as a Tool by setting the parametertool_mode=True. This allows the component to be used in LLM Controls’ Tool Mode workflows, such as by Agent components.
LLM Controls currently supports the following input types for Tool Mode:
DataInputDataFrameInputPromptInputMessageTextInputMultilineInputDropdownInput
Typed annotations
In LLM Controls, typed annotations allow LLM Controls to visually guide users and maintain flow consistency. Typed annotations provide:- Color-coding: Outputs like
-> Dataor-> Messageget distinct colors. - Validation: LLM Controls blocks incompatible connections automatically.
- Readability: Developers can quickly understand data flow.
- Development tools: Better code suggestions and error checking in your code editor.
Common Return Types
Message
For chat-style outputs.
In the UI, connects only to Message-compatible inputs.
Data
For structured data like dicts or partial texts.
In the UI, connects only with DataInput.
DataFrame
For tabular data
In the UI, connects only to DataFrameInput.
Primitive Types (str, int, bool)
Returning primitives is allowed but wrapping in Data or Message is recommended for better UI consistency.
Tips for typed annotations
When using typed annotations, consider the following best practices:- Always Annotate Outputs: Specify return types like
-> Data,-> Message, or-> DataFrameto enable proper UI color-coding and validation. - Wrap Raw Data: Use
Data,Message, orDataFramewrappers instead of returning plain structures. - Use Primitives Carefully: Direct
strorintreturns are fine for simple flows, but wrapping improves flexibility. - Annotate Helpers Too: Even if internal, typing improves maintainability and clarity.
- Handle Edge Cases: Prefer returning structured
Datawith error fields when needed. - Stay Consistent: Use the same types across your components to make flows predictable and easier to build.
Enable dynamic fields
In LLM Controls, dynamic fields allow inputs to change or appear based on user interactions. You can make an input dynamic by settingdynamic=True. Optionally, setting real_time_refresh=True triggers the update_build_config method to adjust the input’s visibility or properties in real time, creating a contextual UI that only displays relevant fields based on the user’s choices.
In this example, the operator field triggers updates via real_time_refresh=True. The regex_pattern field is initially hidden and controlled via dynamic=True.
Implement update_build_config
When a field with real_time_refresh=True is modified, LLM Controls calls the update_build_config method, passing the updated field name, value, and the component’s configuration to dynamically adjust the visibility or properties of other fields based on user input.
This example will show or hide the regex_pattern field when the user selects a different operator.
Additional Dynamic Field Controls
You can also modify other properties withinupdate_build_config, such as:
required: Setbuild_config["some_field"]["required"] = True/Falseadvanced: Setbuild_config["some_field"]["advanced"] = Trueoptions: Modify dynamic dropdown options.
Tips for Managing Dynamic Fields
When working with dynamic fields, consider the following best practices to ensure a smooth user experience:- Minimize field changes: Hide only fields that are truly irrelevant to avoid confusing users.
- Test behavior: Ensure that adding or removing fields doesn’t accidentally erase user input.
- Preserve data: Use
build_config["some_field"]["show"] = Falseto hide fields without losing their values. - Clarify logic: Add
infonotes to explain why fields appear or disappear based on conditions. - Keep it manageable: If the dynamic logic becomes too complex, consider breaking it into smaller components, unless it serves a clear purpose in a single node.
Error handling and logging
In LLM Controls, robust error handling ensures that your components behave predictably, even when unexpected situations occur, such as invalid inputs, external API failures, or internal logic errors.Error handling techniques
- Raise Exceptions: If a critical error occurs, you can raise standard Python exceptions , such as
ValueError, or specialized exceptions likeToolException. LLM Controls will automatically catch these and display appropriate error messages in the UI, helping users quickly identify what went wrong.
Improve debugging and flow management
Useself.status: Each component has a status field where you can store short messages about the execution result—such as success summaries, partial progress, or error notifications. These appear directly in the UI, making troubleshooting easier for users.
Stop specific outputs with self.stop(...): You can halt individual output paths when certain conditions fail, without affecting the entire component. This is especially useful when working with components that have multiple output branches.
Log events: You can log key execution details inside components. Logs are displayed in the “Logs” or “Events” section of the component’s detail view and can be accessed later through the flow’s debug panel or exported files, providing a clear trace of the component’s behavior for easier debugging.
Tips for error handling and logging
To build more reliable components, consider the following best practices:- Validate inputs early: Catch missing or invalid inputs at the start to prevent broken logic.
- Summarize with
self.status: Use short success or error summaries to help users understand results quickly. - Keep logs concise: Focus on meaningful messages to avoid cluttering the UI.
- Return structured errors: When appropriate, return
Data(data={"error": ...})instead of raising exceptions to allow downstream handling. - Stop outputs selectively: Only halt specific outputs with
self.stop(...)if necessary, to preserve correct flow behavior elsewhere.