yaml

YAML loading helpers shared across Pipecat’s YAML-based configuration.

The main helper is include_loader(), which builds a loader class that understands an !include <relative-path> tag so a document can pull in other files:

judge: !include judge_audio.yaml
task_messages: !include prompts/greeting.yaml

A path resolves relative to the file that names it, so an included file’s own includes resolve against its directory. Paths are not confined to that directory; .. and absolute paths reach anywhere the process can read. Use these loaders only on trusted documents.

pipecat.utils.yaml.add_include_constructor(loader_class: type[SafeLoader], base_dir: Path) → None[source]

Register an !include <relative-path> constructor on loader_class.

Paths resolve against base_dir and may reach outside it. An included file loads with a subclass of the loading class whose own includes resolve against that file’s directory, so a fragment’s includes work wherever the fragment is included from, and scalars and constructors get the same treatment as in the top-level document.

This mutates loader_class. Register on a private subclass rather than on yaml.SafeLoader itself so the constructor has no global side effects; include_loader() does that for you.

Parameters:
  • loader_class – The loader class to register the constructor on.

  • base_dir – Directory that !include paths resolve against.

pipecat.utils.yaml.include_loader(base_dir: Path, base: type[SafeLoader] = <class 'yaml.loader.SafeLoader'>) → type[SafeLoader][source]

Build a loader class that resolves !include relative to base_dir.

Returns a fresh subclass of base with the include constructor registered, so base itself is left untouched.

Parameters:
  • base_dir – Directory that the document’s !include paths resolve against, typically the directory of the document being loaded. An included file’s own includes resolve against its directory.

  • base – Loader class to subclass. Defaults to yaml.SafeLoader; pass a custom SafeLoader subclass to keep its resolvers and constructors.

Returns:

A loader class to pass as the Loader argument of yaml.load.

Example:

with path.open() as f:
    data = yaml.load(f, include_loader(path.parent))