Skip to content

Adopt NotBlankStr across all models to eliminate redundant whitespace validators #108

@Aureliolo

Description

@Aureliolo

Problem

core/types.py defines NotBlankStr — a validated string type that rejects empty/whitespace-only values:

NotBlankStr = Annotated[str, StringConstraints(min_length=1), AfterValidator(_check_not_whitespace)]

But it's only used in providers/models.py. Meanwhile, core/agent.py has 6+ manual @model_validator methods doing the same whitespace check:

@model_validator(mode="after")
def _validate_name_not_blank(self) -> Self:
    if not self.name.strip():
        raise ValueError("name must not be blank")
    return self

This pattern repeats across AgentIdentity, PersonalityConfig, SkillSet, ModelConfig, MemoryConfig, ToolPermissions, and potentially other models.

Proposed Solution

Replace all str fields with min_length=1 + whitespace rejection with NotBlankStr:

# Before
name: str = Field(min_length=1)

@model_validator(mode="after")
def _validate_name_not_blank(self) -> Self:
    ...

# After
name: NotBlankStr = Field()
# No validator needed

Scope

Modules to audit and update:

  • core/agent.py (AgentIdentity, PersonalityConfig, SkillSet, ModelConfig, etc.)
  • core/task.py (Task)
  • config/schema.py (config models)
  • templates/ (template models)
  • budget/ (spending summary models — agent_id, department fields)
  • providers/ (already partially adopted)
  • tools/base.py (BaseTool.name)

Acceptance Criteria

  • All str fields with min_length=1 that reject whitespace use NotBlankStr
  • Redundant _validate_non_blank* / _validate_*_not_blank validators removed
  • Model validators that check other things (e.g., cross-field logic) are preserved
  • All existing tests pass (may need minor error message adjustments)
  • No net increase in line count
  • Verify DESIGN_SPEC.md §3.1 NotBlankStr reference and CLAUDE.md Models convention remain consistent after implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:highImportant, should be prioritizedscope:medium1-3 days of worktype:refactorCode restructuring, cleanup

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions