baml.io.input

Reads a line of text from stdin. If `prompt` is provided, it is printed first (without a newline).

Reference version

Signature

function baml.io.input(prompt: string | null) -> string throws baml.errors.Io

Reads a line of text from stdin. If prompt is provided, it is printed first (without a newline).

The trailing newline is stripped; end-of-input reads as "".

Unlike the print family — which panics with baml.panics.HostUnavailable on a dead output stream, as Rust's println! does — reading input is an operation callers routinely want to handle, so a failed read is an error value.

Throws

  • Io if the prompt cannot be written or stdin cannot be read.

Source:<builtin>/baml/ns_io/io.bamlbytes 515–604