yera.dsl.functions
Prompting, input, output, layout, and lifecycle functions.
The building blocks an app function uses to interact with the LLM, present output, and collect input from the user.
Prompting
chat: send a prompt and get a text responsesys_prompt: append a line to the active system prompt
Input widgets
text_input: free-form textbuttons: pick one of a set of optionsdate_picker: pick a dateslider: pick a number in a rangetree_selector: select leaves from a nested tree
Output blocks
markdown: render markdown contenttable: render tabular dataspinner: show a spinner while work runsresultimage: render image-file bytes
Layout
section— group related output blocks
Lifecycle
session_title: set the title associated with the current sessionexit: end the app runquit: end the app run as a user-initiated quit
Symbols
bar_chart
bar_chart(
data: object,
x: str | None = None,
y: str | Sequence[str] | None = None,
colour: str | Sequence[str] | None = None,
horizontal: bool = False,
stack: bool = True,
) → NoneRender a bar chart.
Parameters
Chart data; typically a pandas DataFrame.
Column name to use for the x-axis.
Column name (or names) to plot on the y-axis.
Column name (or names) used to colour the bars.
Orient bars horizontally rather than vertically.
Stack multiple series rather than grouping side-by-side.
Examples
import pandas as pd
df = pd.DataFrame({"quarter": ["Q1", "Q2", "Q3", "Q4"], "revenue": [120, 145, 98, 167]})
bar_chart(df, x="quarter", y="revenue")
Grouped by colour:
df = pd.DataFrame({
"quarter": ["Q1", "Q2", "Q1", "Q2"],
"revenue": [120, 145, 98, 167],
"region": ["North", "North", "South", "South"],
})
bar_chart(df, x="quarter", y="revenue", colour="region", stack=False)
buttons
buttons(
options: list[str],
label: str | None = None,
) → strPresent the user with a set of buttons and return their selection.
Parameters
Labels for the buttons to display.
Optional prompt shown above the buttons.
Returns
The label of the button the user clicked.
chat
chat(
stop_str: str = '/quit',
) → Generator[str]Yield user prompts until one starts with stop_str.
Repeatedly prompts the user for text input, yielding each prompt.
When the user submits a prompt starting with stop_str, the run
quits and iteration stops.
Parameters
Prefix that, when matched, ends the chat loop. Default = "/quit"
confirm
confirm(
label: str | None = None,
true_option: str = 'Yes',
false_option: str = 'No',
) → boolPresent the user with a binary choice and return True/False.
Parameters
optional prompt shown above the buttons.
the button option representing true.
the button option representing false.
Returns
boolean value representing whether the user chose the true or false option.
date_picker
date_picker(
label: str,
default_date: date | str | None = None,
) → datePresent the user with a date picker.
Parameters
Prompt shown alongside the picker.
Optional initial date, as a date or ISO-format
string.
Returns
The date the user chose.
exit
exit(
exit_code: int,
reason: str,
return_value: object,
error_cause: ErrorCause | None = None,
) → NoneEnd the current app run.
Parameters
Process-style exit code; 0 for success, non-zero
for failure.
Human-readable summary of why the run ended.
Value to return to the caller, or None.
Optional structured cause metadata for failure exits.
See ErrorCause.
gen
gen(
on_wire: bool = True,
instruction: str | None = None,
**kwargs,
) → strGenerate a response from the active LLM with optional instruction and visibility control.
Parameters
Whether to include the response back in the LLM context.
Optional system instruction to guide generation (e.g., for structured outputs).
Additional keyword arguments passed directly to the underlying LLM
(e.g., temperature, max_tokens, etc.).
Returns
The generated text response from the LLM.
image
image(
content: bytes,
media_type: ImageMediaType = 'image/png',
alt: str | None = None,
) → NoneRender an image from image-file bytes.
The image is fitted responsively to the available display width while preserving its intrinsic aspect ratio. PNG, JPEG, WebP, GIF, and SVG images are supported. Rendering depends on the active output environment.
Parameters
Raw contents of a PNG, JPEG, WebP, GIF, or SVG image file.
MIME type identifying the supplied image format.
Optional accessible description of the image.
insert
insert(
prompt: str,
) → NoneInsert a prompt into the active LLM context.
Unlike response, this does not
generate a response; it merely appends the given prompt to the conversation history.
Parameters
The user message to insert into the LLM context.
line_chart
line_chart(
data: object,
x: str | None = None,
y: str | Sequence[str] | None = None,
colour: str | Sequence[str] | None = None,
) → NoneRender a line chart.
Parameters
Chart data; typically a pandas DataFrame.
Column name to use for the x-axis.
Column name (or names) to plot on the y-axis.
Column name (or names) used to colour the lines.
Examples
import pandas as pd
df = pd.DataFrame({"time": [1, 2, 3], "value": [4, 5, 6]})
line_chart(df, x="time", y="value")
markdown
markdown(
content: str,
) → NoneRender a markdown block.
Can be called directly to emit a single block, or used as a stream handle to append further chunks over time.
Parameters
the markdown content to display
quit
quit() → NoneEnd the current app run as a user-initiated quit.
Distinct from exit: signals that the
user chose to stop rather than the app completing or failing.
response
response(
prompt: str,
**kwargs,
) → strSend a prompt to the active LLM and return its text response.
Tokens will simultaneously be pushed onto the event stream for display in your UI or printed to stdout.
Parameters
The user-message prompt to send.
Additional options forwarded to the underlying LLM (e.g. provider-specific generation parameters).
Returns
The LLM's text response.
section
section(
title: str,
summary: str | None = None,
auto_collapse: bool = True,
glyph: str = 'thread',
colour: NamedColour | None = None,
) → SectionGroup output blocks into a mutable, collapsible section.
Sections may contain ordinary output blocks or nested sections. While the
context is open, its title, glyph, and colour may be changed through the
returned section object. The success() and error() methods apply
standard completion appearances without closing the section. In the web UI,
the section may collapse automatically when its context exits.
Parameters
Heading shown in the section header.
Optional summary shown for the completed section.
Whether the section collapses when it completes.
Name of the glyph shown in the section header.
Optional named colour applied to the section heading.
Returns
A Section context manager.
Examples
with section("Loading data", glyph="spinner") as current:
load_data()
current.success("Data loaded")
session_title
session_title(
title: str,
) → NoneSet the title associated with the current session.
Session-aware hosts may persist and display the title. In runtimes without sessions, the emitted metadata update has no persistent effect.
Parameters
Title to associate with the current session.
slider
slider(
min_value: float,
max_value: float,
label: str,
default_value: float | None = None,
) → floatPresent the user with a slider over a numeric range.
Parameters
Lower bound of the slider.
Upper bound of the slider.
Prompt shown alongside the slider.
Optional initial position. Defaults to
min_value if not provided.
Raises
If the submitted value is outside the slider range.
Returns
The value the user selected.
spinner
spinner(
message: str = 'Working',
glyph: str = 'run',
colour: NamedColour = 'orange',
end_message: str = 'Done',
end_glyph: str = 'check',
end_colour: NamedColour = 'green',
) → SpinnerStreamShow a configurable spinner while a block of work runs.
The spinner may change its message, glyph, and colour while active. On successful exit it resolves to the configured completion appearance; on exceptional exit it uses the fixed failure appearance.
Parameters
Initial message shown alongside the spinner.
Initial registered glyph name.
Initial named colour.
Message shown after successful completion.
Registered glyph shown after successful completion.
Named colour shown after successful completion.
Returns
A SpinnerStream context manager.
sys_prompt
sys_prompt(
prompt: str,
) → NoneAppend a line to the active LLM context's system prompt.
Parameters
Text to add to the system prompt for subsequent
chat and struct calls in the current LLM context.
table
table(
data: object = None,
border: bool | Literal['horizontal'] = True,
) → TableStreamRender a table.
Parameters
Table data. Accepts pandas DataFrames, dicts of column
lists, lists of dicts, lists of lists, or any iterable that
can be converted to rows. Pass None for an empty table.
True for full borders, False for none, or
"horizontal" for horizontal lines only.
Returns
A TableStream handle whose add_rows method appends rows to the same table.
text_input
text_input(
message: str | None = None,
) → strPrompt the user for free-form text input.
Parameters
Optional label shown alongside the input field.
Returns
The text the user submitted.
tree_selector
tree_selector(
tree: TreeSelectorSource,
label: str | None = None,
min_selections: int = 1,
max_selections: int | None = None,
) → list[str]Present a nested tree and return the selected leaf values.
Parameters
Nested option mapping or an object implementing
__yera_tree__().
Optional prompt shown above the tree.
Minimum number of leaves that must be selected.
Optional maximum number of leaves that may be selected.
Raises
If the source cannot provide a valid tree mapping.
If the supplied tree is malformed.
If the submitted selection violates its cardinality, contains duplicates, or includes a value outside the requested tree.
Returns
The canonical values of the selected leaves, in submitted order.