Back to Skills

config-skills

majiayu000
Updated Yesterday
2 views
58
9
58
View on GitHub
Metageneral

About

This skill provides configuration module patterns for LlamaFarm using Pydantic v2 models with JSONSchema validation. It covers YAML/TOML/JSON processing, schema generation, and custom validation logic. Use this when implementing structured configuration systems with type-safe loading and validation.

Quick Install

Claude Code

Recommended
Plugin CommandRecommended
/plugin add https://github.com/majiayu000/claude-skill-registry
Git CloneAlternative
git clone https://github.com/majiayu000/claude-skill-registry.git ~/.claude/skills/config-skills

Copy and paste this command in Claude Code to install this skill

Documentation

Config Skills for LlamaFarm

Specialized patterns and best practices for the LlamaFarm configuration module (config/).

Module Overview

The config module provides YAML/TOML/JSON configuration loading with JSONSchema validation:

FilePurpose
datamodel.pyGenerated Pydantic v2 models from JSONSchema
schema.yamlSource JSONSchema with $ref references
compile_schema.pyDereferences $ref to create schema.deref.yaml
generate_types.pyGenerates Python types via datamodel-codegen
validators.pyCustom validators beyond JSONSchema capabilities
helpers/loader.pyConfig loading, saving, and format detection
helpers/generator.pyTemplate-based config generation

Links to Shared Skills

This module follows Python conventions from the shared skills:

TopicLinkKey Relevance
Patternspython-skills/patterns.mdPydantic v2, dataclasses
Typingpython-skills/typing.mdType hints, constrained types
Testingpython-skills/testing.mdPytest fixtures, temp files
Errorspython-skills/error-handling.mdCustom exceptions
Securitypython-skills/security.mdPath traversal prevention

Framework-Specific Checklists

ChecklistDescription
pydantic.mdPydantic v2 configuration patterns, nested models, constraints
jsonschema.mdJSONSchema generation, dereferencing, validation

Tech Stack

  • Python: 3.11+
  • Pydantic: v2 with ConfigDict, Field, constrained types
  • JSONSchema: Draft-07 with $ref dereferencing via jsonref
  • YAML: ruamel.yaml for comment-preserving read/write
  • Code Generation: datamodel-codegen for schema-to-Pydantic

Key Patterns

Generated Pydantic Models

The datamodel.py file is auto-generated from JSONSchema:

# Generated by datamodel-codegen from schema.deref.yaml
from pydantic import BaseModel, ConfigDict, Field, conint, constr

class Database(BaseModel):
    model_config = ConfigDict(extra="forbid")
    name: constr(pattern=r"^[a-z][a-z0-9_]*$", min_length=1, max_length=50)
    type: Type
    config: dict[str, Any] | None = Field(None, description="Database-specific configuration")

Custom Validators for Cross-Field Constraints

JSONSchema draft-07 cannot express all constraints. Custom validators extend validation:

def validate_llamafarm_config(config_dict: dict[str, Any]) -> None:
    """Validate constraints beyond JSONSchema (uniqueness, references)."""
    # Check for duplicate prompt names
    prompt_names = [p.get("name") for p in config_dict.get("prompts", [])]
    duplicates = [name for name in prompt_names if prompt_names.count(name) > 1]
    if duplicates:
        raise ValueError(f"Duplicate prompt set names: {', '.join(set(duplicates))}")

Comment-Preserving YAML with ruamel.yaml

Configuration files preserve user comments when modified:

from ruamel.yaml import YAML
from ruamel.yaml.comments import CommentedMap

def _get_ruamel_yaml() -> YAML:
    yaml_instance = YAML()
    yaml_instance.preserve_quotes = True
    yaml_instance.indent(mapping=2, sequence=4, offset=2)
    return yaml_instance

Directory Structure

config/
├── pyproject.toml       # UV-managed dependencies
├── schema.yaml          # Source JSONSchema with $ref
├── schema.deref.yaml    # Dereferenced schema (generated)
├── datamodel.py         # Pydantic models (generated)
├── compile_schema.py    # Schema compilation script
├── generate_types.py    # Type generation script
├── validators.py        # Custom validation beyond JSONSchema
├── validate_config.py   # CLI validation wrapper
├── __init__.py          # Public API exports
├── helpers/
│   ├── loader.py        # Config loading/saving
│   └── generator.py     # Template-based generation
├── templates/
│   └── default.yaml     # Default config template
└── tests/
    ├── conftest.py      # Shared fixtures
    └── test_*.py        # Test modules

Workflow: Schema Changes

When modifying the configuration schema:

  1. Edit schema.yaml (or referenced schemas like ../rag/schema.yaml)
  2. Run nx run generate-types to compile and generate types
  3. Update validators.py if new cross-field constraints are needed
  4. Test with uv run pytest config/tests/

Common Commands

# Generate types from schema
nx run generate-types

# Validate a config file
uv run python config/validate_config.py path/to/llamafarm.yaml --verbose

# Run tests
uv run pytest config/tests/ -v

# Lint and format
ruff check config/ --fix
ruff format config/

GitHub Repository

majiayu000/claude-skill-registry
Path: skills/config-skills

Related Skills

algorithmic-art

Meta

This Claude Skill creates original algorithmic art using p5.js with seeded randomness and interactive parameters. It generates .md files for algorithmic philosophies, plus .html and .js files for interactive generative art implementations. Use it when developers need to create flow fields, particle systems, or other computational art while avoiding copyright issues.

View skill

subagent-driven-development

Development

This skill executes implementation plans by dispatching a fresh subagent for each independent task, with code review between tasks. It enables fast iteration while maintaining quality gates through this review process. Use it when working on mostly independent tasks within the same session to ensure continuous progress with built-in quality checks.

View skill

executing-plans

Design

Use the executing-plans skill when you have a complete implementation plan to execute in controlled batches with review checkpoints. It loads and critically reviews the plan, then executes tasks in small batches (default 3 tasks) while reporting progress between each batch for architect review. This ensures systematic implementation with built-in quality control checkpoints.

View skill

cost-optimization

Other

This Claude Skill helps developers optimize cloud costs through resource rightsizing, tagging strategies, and spending analysis. It provides a framework for reducing cloud expenses and implementing cost governance across AWS, Azure, and GCP. Use it when you need to analyze infrastructure costs, right-size resources, or meet budget constraints.

View skill