agentleFS
Microsoft AzureKnown publisherAzure/azure-cli/.github/skills/common-aaz-custom-code-generation/SKILL.md

common-aaz-custom-code-generation

Skill4.6k starsChanged 3 months agoMITView on GitHub

Use after routing to AAZ subclass custom, or when adding/updating Azure CLI AAZ generated command customization. Generates custom classes that subclass AAZ generated commands while limiting uncertainty with required slots, templates, and validation gates.

Trending

Quiet this year.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the Azure/azure-cli repository that our weekly crawl found: only 5 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

The file

Show its rules and text

We split this skill into the rules it gives an agent

39 rules. About 0 are common, 26 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈26

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Use this workflow to generate or update hand-written custom code for Azure CLI commands whose primary implementation is an AAZ generated …

    line 9
  2. Distinctive:

    Use this skill for:

    line 17
  3. Distinctive:

    Do not use this skill for:

    line 26
  4. Very specific:

    Read the generated _create.py, _show.py, _list.py, _update.py, _delete.py, or _wait.py enough to confirm:

    line 59
  5. Very specific:

    Search the target module for existing class XxxCustom(GeneratedClass) patterns.

    line 64
  6. Very specific:

    Search commands.py or the module loader for existing command table replacement style.

    line 65
  7. Distinctive:

    Before generating code, reduce uncertainty with these gates:

    line 70
  8. Distinctive:

    If the generated command path is missing, do not create an AAZ subclass.

    line 72
  9. Very specific:

    If the requested behavior requires a new REST operation not present in generated AAZ code, do not invent AAZHttpOperation by hand in custom …

    line 73
  10. Distinctive:

    If the behavior can be expressed as schema customization, argument normalization/validation, or resource/operation guard checks, subclass …

    line 74
  11. Distinctive:

    If multiple customization goals apply, keep one custom class and combine the smallest necessary hooks.

    line 75
  12. Very specific:

    If a guard check requires raw HTTP or a secondary command invocation, keep it isolated in pre_operations or post_operations and validate …

    line 76
  13. Distinctive:

    If the module already has a local helper for shared schema or validation, reuse it instead of duplicating logic.

    line 77
  14. Distinctive:

    Add imports in the manual code file:

    line 81
  15. Distinctive:

    Add helper functions only when shared by multiple custom classes or when they reduce repeated validation/schema code.

    line 85
  16. Distinctive:

    Add a custom class that subclasses the generated base class.

    line 86
  17. Very specific:

    Update parameters/help/tests only if the module's AAZ/manual help pattern requires it or the user requested examples/tests.

    line 89
  18. Distinctive:

    Run the narrowest validation available: command load, help for the target command, a focused unit test, or a targeted scenario test.

    line 90
  19. Distinctive:

    If no template matches the requested business logic, do not force the request into one of these examples.

    line 98
  20. Distinctive:

    Use this when generated arguments need aliases, relaxed required flags, additional CLI-only arguments, or hidden generated arguments.

    line 110
  21. Distinctive:

    Use this when user-friendly CLI arguments must be converted into the generated AAZ argument shape before the HTTP operation runs.

    line 138
  22. Very specific:

    Use azure.mgmt.core.tools.is_valid_resource_id when accepting resource IDs.

    line 164
  23. Very specific:

    Use this when create/update/delete must check resource existence, dependencies, or state before or after the generated operation.

    line 168
  24. Distinctive:

    Call an argument normalization helper first only if the guard check depends on the normalized argument value.

    line 177
  25. Very specific:

    When using send_raw_request, keep URL construction explicit and validate any resource URI before concatenating it.

    line 179
  26. Distinctive:

    Prefer generated AAZ operations or existing SDK helpers over raw HTTP when a local pattern exists.

    line 203
  27. Distinctive:

    Use this when the command needs both CLI-friendly arguments and generated argument normalization.

    line 207
  28. Distinctive:

    Use this when replacing the generated AAZ command class with the custom subclass.

    line 222
  29. Distinctive:

    If the module already uses a different manual registration style for AAZ custom classes, follow that local style exactly.

    line 231
  30. Very specific:

    If blocked_on is non-empty, ask a focused question instead of generating code.

    line 253
  31. Distinctive:

    After editing, report the files changed and the validation command/result.

    line 255
  32. Distinctive:

    Prefer the narrowest validation available:

    line 259
  33. Distinctive:

    If the generated command cannot be loaded because dependencies are unavailable in the local environment, state that clearly and provide the …

    line 266
  34. Very specific:

    Do not edit generated AAZ files under aaz/latest for manual customization.

    line 270
  35. Very specific:

    Do not copy generated operation classes into custom.py.

    line 271
  36. Distinctive:

    Do not invent argument names.

    line 272
  37. Very specific:

    Do not assume every AAZ custom needs resource_group and name aliases.

    line 273
  38. Distinctive:

    Do not overwrite command table entries before confirming the full command key.

    line 274
  39. Distinctive:

    Do not swallow non-404 HTTP errors in pre-operation checks.

    line 275

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Common AAZ Custom Code Generation

Use this workflow to generate or update hand-written custom code for Azure CLI commands whose primary implementation is an AAZ generated command.

This skill starts after the route is known or strongly suspected to be aaz-subclass-custom. If the route is unclear, use common-custom-code-router first.

Scope

This is module-general and applies across Azure CLI command modules under src/azure-cli/azure/cli/command_modules.

Use this skill for:

  • subclassing generated AAZ command classes such as Create, Show, List, Update, Delete, or Wait
  • changing generated command argument UX through _build_arguments_schema
  • normalizing or validating CLI arguments before generated operations run
  • adding resource or operation guard checks around a generated command, such as existence checks or dependency checks
  • shaping generated command output when local module patterns support it
  • replacing a generated command table entry with a hand-written subclass

Do not use this skill for:

  • legacy SDK-backed custom functions using CliCommandType(..., client_factory=...)
  • Legacy Non-SDK Custom: local tool, subprocess, data-plane, raw HTTP, or diagnostic workflows whose public command is not an AAZ subclass
  • editing generated files under aaz/latest unless the user explicitly asks to modify generated output and accepts regeneration risk

Slots To Resolve

Resolve these slots before editing the related code. Prefer repository evidence over asking the user. These are not all user-provided inputs; some are derived or conditional.

module_name: "<module under command_modules>"
command_group: "<az command group, e.g. network vnet or aks safeguards>"
command_verb_or_action: "<CLI verb/action used to locate the generated file, e.g. create/show/wait or custom action>"
generated_module_import: "<relative import from .aaz.latest...>"
generated_base_class: "<Python class imported from the generated module and inherited by the custom class, e.g. Create/Show/Wait>"
custom_class_name: "<ModuleResourceVerbCustom>"
manual_code_file: "<custom.py or module-local manual file>"
command_table_key: "<full command name; required only when replacing a command_table entry; derive from @register_command(...) when possible>"
registration_file: "<commands.py or loader file; required only when adding/updating a command_table override>"
customization_goals: "<schema-extension | argument-normalization | argument-validation | resource-guard | operation-guard | output-shaping | wait-customization>"
validation_command: "<narrow command-load/help/test command or unknown>"

command_verb_or_action and generated_base_class often correspond for standard commands, but they are not the same slot. The verb/action helps locate generated files such as _show.py or _wait.py; the base class is the concrete Python class the custom class will inherit.

If generated_module_import or generated_base_class cannot be resolved, stop and ask one focused question or ask for the generated command path. Do not guess an AAZ import path. If command_table_key cannot be resolved but no command table override is needed, set it to not-needed. If an override is needed and the key cannot be derived, ask one focused question.

Evidence To Gather

Gather only the evidence needed for the slots.

  1. Confirm the generated command exists under src/azure-cli/azure/cli/command_modules/<module>/aaz/latest/....
  2. Read the generated _create.py, _show.py, _list.py, _update.py, _delete.py, or _wait.py enough to confirm:
    • command name in _aaz_info or examples
    • generated class name
    • argument names in _build_arguments_schema
    • operation hooks available in the class
  3. Search the target module for existing class XxxCustom(GeneratedClass) patterns.
  4. Search commands.py or the module loader for existing command table replacement style.
  5. Inspect the nearest sibling command with the same verb or resource family.

Uncertainty Gates

Before generating code, reduce uncertainty with these gates:

  • If the generated command path is missing, do not create an AAZ subclass. Route back to SDK or non-SDK evaluation.
  • If the requested behavior requires a new REST operation not present in generated AAZ code, do not invent AAZHttpOperation by hand in custom code.
  • If the behavior can be expressed as schema customization, argument normalization/validation, or resource/operation guard checks, subclass the generated command instead of copying generated code.
  • If multiple customization goals apply, keep one custom class and combine the smallest necessary hooks.
  • If a guard check requires raw HTTP or a secondary command invocation, keep it isolated in pre_operations or post_operations and validate inputs before constructing URLs.
  • If the module already has a local helper for shared schema or validation, reuse it instead of duplicating logic.

Implementation Workflow

  1. Add imports in the manual code file:
    • AAZ argument helpers from azure.cli.core.aaz only when needed.
    • The generated base class from .aaz.latest....
    • Existing local validators/helpers when available.
  2. Add helper functions only when shared by multiple custom classes or when they reduce repeated validation/schema code.
  3. Add a custom class that subclasses the generated base class.
  4. Override only the hooks needed for the requested behavior.
  5. Register the custom class by replacing the generated command table entry in the module's command registration file.
  6. Update parameters/help/tests only if the module's AAZ/manual help pattern requires it or the user requested examples/tests.
  7. Run the narrowest validation available: command load, help for the target command, a focused unit test, or a targeted scenario test.

Hook Templates

Use only the templates needed by the requested behavior. Treat templates as patterns, not fixed implementations. Replace every placeholder and every example argument with names found in the generated AAZ schema or the target module's local conventions. Never leave angle-bracket placeholders such as <AAZArgType> or <generated_arg_name> in generated code.

Fallback: Unmatched Business Logic

If no template matches the requested business logic, do not force the request into one of these examples. First identify the smallest AAZ hook that can express the behavior:

  • _build_arguments_schema for CLI argument surface changes
  • pre_operations for validation, normalization, or checks before generated operations
  • post_operations for checks or output changes after generated operations
  • _output only when local module patterns support custom output shaping
  • another generated lifecycle hook only after reading the generated base class and confirming the hook exists

Then generate the smallest subclass that overrides only that hook. If the behavior requires replacing the generated REST operation itself, route back to evaluation instead of stretching these templates.

Template: Schema Extension

Use this when generated arguments need aliases, relaxed required flags, additional CLI-only arguments, or hidden generated arguments.

from azure.cli.core.aaz import <AAZArgType>
from .aaz.latest.<resource_path>._<verb> import <GeneratedBase>


def _add_<resource>_args(args_schema):
    args_schema.<new_cli_arg_name> = <AAZArgType>(
        options=["--<option-name>"],
        required=<TrueOrFalse>,
        help="<help text>",
    )
    args_schema.<generated_arg_name>._required = False  # pylint: disable=protected-access
    return args_schema


class <CustomClassName>(<GeneratedBase>):
    @classmethod
    def _build_arguments_schema(cls, *args, **kwargs):
        args_schema = super()._build_arguments_schema(*args, **kwargs)
        return _add_<resource>_args(args_schema)

Replace placeholder argument names with real generated argument names. Do not add resource_group, name, resource_id, or any other example argument unless it matches the command's UX and generated schema.

Template: Argument Normalization Or Validation

Use this when user-friendly CLI arguments must be converted into the generated AAZ argument shape before the HTTP operation runs.

from azure.cli.core.aaz import has_value
from azure.cli.core.azclierror import ArgumentUsageError


def _validate_and_set_<resource>_argument(ctx):
    args = ctx.args
    has_generated_arg = has_value(args.<generated_arg_name>)
    has_cli_arg_set = has_value(args.<cli_arg_name>)

    if has_generated_arg == has_cli_arg_set:
        raise ArgumentUsageError(
            "Provide either '<generated option>' or '<friendly option set>', but not both."
        )

    if not has_generated_arg:
        args.<generated_arg_name> = <normalize_cli_args_to_generated_value>(ctx, args)


class <CustomClassName>(<GeneratedBase>):
    def pre_operations(self):
        _validate_and_set_<resource>_argument(self.ctx)

Use azure.mgmt.core.tools.is_valid_resource_id when accepting resource IDs. Normalize and validate resource IDs before using them in URLs. For non-resource-ID arguments, use the generated schema and neighboring command behavior to choose validation rules.

Template: Resource Or Operation Guard Check

Use this when create/update/delete must check resource existence, dependencies, or state before or after the generated operation.

class <CustomClassName>(<GeneratedBase>):
    def pre_operations(self):
        super().pre_operations()
        _check_<condition>(self.ctx)

Call an argument normalization helper first only if the guard check depends on the normalized argument value.

When using send_raw_request, keep URL construction explicit and validate any resource URI before concatenating it. Use raw HTTP only as a small guard around an AAZ subclass; if raw HTTP is the primary command implementation, route to legacy non-SDK custom instead.

def _check_<condition>(ctx):
    from azure.cli.core.azclierror import HTTPError
    from azure.cli.core.util import send_raw_request
    from knack.util import CLIError

    resource_uri = ctx.args.<resource_id_arg>.to_serialized_data()
    if not resource_uri.startswith("/subscriptions/"):
        raise CLIError(f"Invalid resource ID format: {resource_uri}")

    url = f"https://management.azure.com{resource_uri}/providers/<Provider>/<childType>/default?api-version=<api-version>"
    try:
        response = send_raw_request(ctx.cli_ctx, "GET", url)
    except HTTPError as ex:
        if ex.response.status_code == 404:
            return
        raise

    if response.status_code == 200:
        raise CLIError("The resource already exists. Use update to modify it or delete it before creating a new one.")

Prefer generated AAZ operations or existing SDK helpers over raw HTTP when a local pattern exists.

Template: Combined Schema And Pre-Operation Custom Class

Use this when the command needs both CLI-friendly arguments and generated argument normalization.

class <CustomClassName>(<GeneratedBase>):
    @classmethod
    def _build_arguments_schema(cls, *args, **kwargs):
        args_schema = super()._build_arguments_schema(*args, **kwargs)
        return _add_<resource>_args(args_schema)

    def pre_operations(self):
        _validate_and_set_<resource>_argument(self.ctx)

Template: Command Table Override

Use this when replacing the generated AAZ command class with the custom subclass.

with self.command_group('<command_group>'):
    from .custom import <CustomClassName>

    self.command_table["<full command name>"] = <CustomClassName>(loader=self)

If the module already uses a different manual registration style for AAZ custom classes, follow that local style exactly.

Output Expectations

Before editing, report:

route: aaz-subclass-custom
module_name: "..."
command_verb_or_action: "..."
generated_module_import: "..."
generated_base_class: "..."
custom_class_name: "..."
command_table_key: "... | not-needed"
registration_file: "... | not-needed"
customization_goals: "..."
planned_hooks:
  - "_build_arguments_schema"
  - "pre_operations"
blocked_on: []

If blocked_on is non-empty, ask a focused question instead of generating code.

After editing, report the files changed and the validation command/result.

Validation

Prefer the narrowest validation available:

  1. az <target command> -h or the repo's equivalent command-load/help test command.
  2. A focused existing unit test for the target module.
  3. A command table import/load check for the target module.
  4. git status --short and a diff review only when executable validation is unavailable.

If the generated command cannot be loaded because dependencies are unavailable in the local environment, state that clearly and provide the attempted command.

Common Mistakes To Avoid

  • Do not edit generated AAZ files under aaz/latest for manual customization.
  • Do not copy generated operation classes into custom.py.
  • Do not invent argument names; read the generated argument schema first.
  • Do not assume every AAZ custom needs resource_group and name aliases.
  • Do not overwrite command table entries before confirming the full command key.
  • Do not swallow non-404 HTTP errors in pre-operation checks.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.