Skip to content

validate_notebook_name

Public callable

Validate notebook names against the framework workspace notebook model.

Parameters:

Name Type Description Default
name str | None

Notebook name to validate. When omitted, the function attempts to infer the current Fabric notebook name from runtime context.

None
local_fallback_name str | None

Local-development-only fallback when running outside Fabric runtime.

None
allowed_prefixes list[str] | None

Optional legacy prefix list retained for backward compatibility with older projects. New projects should use the default finalized model: 00_env_config, 01_data_sharing_agreement_<agreement>, 02_ex_<agreement>_<topic>, and 03_pc_<agreement>_<from>_to_<to>.

None

Returns:

Type Description
list[str]

Validation error messages. An empty list means the name is valid.

Examples:

>>> validate_notebook_name("00_env_config")
[]
>>> validate_notebook_name("03_pc_email_metadata_source_to_unified")
[]
Source code in src/fabricops_kit/runtime.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
def validate_notebook_name(name: str | None = None, allowed_prefixes: list[str] | None = None, config: object | None = None, local_fallback_name: str | None = None) -> list[str]:
    """Validate notebook names against the framework workspace notebook model.

    Parameters
    ----------
    name : str | None, optional
        Notebook name to validate. When omitted, the function attempts to infer
        the current Fabric notebook name from runtime context.
    local_fallback_name : str | None, optional
        Local-development-only fallback when running outside Fabric runtime.
    allowed_prefixes : list[str] | None, optional
        Optional legacy prefix list retained for backward compatibility with
        older projects. New projects should use the default finalized model:
        ``00_env_config``, ``01_data_sharing_agreement_<agreement>``,
        ``02_ex_<agreement>_<topic>``, and
        ``03_pc_<agreement>_<from>_to_<to>``.

    Returns
    -------
    list[str]
        Validation error messages. An empty list means the name is valid.

    Examples
    --------
    >>> validate_notebook_name("00_env_config")
    []
    >>> validate_notebook_name("03_pc_email_metadata_source_to_unified")
    []
    """
    errors: list[str] = []
    runtime_name = name or _infer_notebook_name_from_runtime() or local_fallback_name
    normalized_name = (runtime_name or "").strip()
    if not normalized_name:
        errors.append("Notebook name must not be empty.")
        return errors

    if normalize_name(normalized_name) != normalized_name:
        errors.append(
            "Notebook name should be lowercase with underscores only (no spaces or unsafe characters)."
        )
        return errors

    if allowed_prefixes is None and config is not None:
        runtime_config = getattr(config, "notebook_runtime_config", None)
        config_prefixes = getattr(runtime_config, "allowed_notebook_prefixes", None)
        if config_prefixes:
            allowed_prefixes = list(config_prefixes)

    if allowed_prefixes:
        if not any(normalized_name.startswith(prefix) for prefix in allowed_prefixes):
            prefix_list = ", ".join(allowed_prefixes)
            errors.append(
                f"Notebook name '{normalized_name}' must start with one of: {prefix_list}."
            )
        return errors

    agreement_segment = r"[a-z0-9]+(?:_[a-z0-9]+)*"
    notebook_patterns = (
        r"^00_env_config$",
        rf"^01_data_sharing_agreement_{agreement_segment}$",
        rf"^02_ex_{agreement_segment}_{agreement_segment}$",
        rf"^03_pc_{agreement_segment}_{agreement_segment}_to_{agreement_segment}$",
    )
    if not any(re.fullmatch(pattern, normalized_name) for pattern in notebook_patterns):
        errors.append(
            "Notebook name must follow one of: "
            "00_env_config, "
            "01_data_sharing_agreement_<agreement>, "
            "02_ex_<agreement>_<topic>, or "
            "03_pc_<agreement>_<from>_to_<to>."
        )

    return errors