# validate_argspec

Validate an argspec string and inspect the parsed argument slots.

https://texform.dev/api/python/validate-argspec

## `validate_argspec`

Kind: function

```python
validate_argspec(spec: str) -> ValidateArgspecResult
```

Validate an xparse-style argspec string and report its parsed slots.

Use it to self-check an argspec before injecting a custom command into a
``Parser``. It never raises on a malformed spec; instead the result's
``valid`` is ``False`` and ``error`` carries the reason.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `spec` | str | — | The argspec string, such as ``"o m"``, ``"s m{}"``, or ``"d<(,)><[,]>"``. |

**Returns** `ValidateArgspecResult` A ``ValidateArgspecResult`` dict: ``valid``, ``error``, ``arg_count``, and ``parsed`` (the per-slot breakdown when valid).

```python
texform.validate_argspec("o m")  # {'valid': True, 'error': None, 'arg_count': 2, 'parsed': [...]}
```

- [ValidateArgspecResult](https://texform.dev/api/python/validate-argspec.md#ValidateArgspecResult)
- [ParsedArgSpecSlot](https://texform.dev/api/python/validate-argspec.md#ParsedArgSpecSlot)

## `ValidateArgspecResult`

Kind: typedDict

The outcome of validating an argspec string with ``validate_argspec``.

On success, ``valid`` is ``True`` and ``arg_count`` / ``parsed`` describe the
slots; on failure, ``valid`` is ``False`` and ``error`` carries the reason
while ``arg_count`` and ``parsed`` are ``None``.

| Name | Type | Description |
| --- | --- | --- |
| `valid` | bool | Whether the specification string parsed. |
| `error` | str | None | The error message when invalid, otherwise ``None``. |
| `arg_count` | int | None | The number of argument slots when valid, otherwise ``None``. |
| `parsed` | list[ParsedArgSpecSlot] | None | The per-slot breakdown when valid, otherwise ``None``. |

- [validate_argspec](https://texform.dev/api/python/validate-argspec.md#validate_argspec)
- [ParsedArgSpecSlot](https://texform.dev/api/python/validate-argspec.md#ParsedArgSpecSlot)

## `ParsedArgSpecSlot`

Kind: typedDict

One parsed argument slot of an xparse-style specification.

A presentation-oriented view of the internal argspec model, so tooling can
consume argspecs without depending on internal crates.

| Name | Type | Description |
| --- | --- | --- |
| `required` | bool | Whether the argument is mandatory (``True``) or optional. |
| `no_leading_space` | bool | Whether leading whitespace before the argument is disallowed. |
| `nullable` | bool | Whether an absent optional argument yields a null value. |
| `kind` | dict[str, Any] | The value kind the slot accepts; a dict with a ``type`` field, one of the ``ArgSpecKindType`` values. A ``content`` kind also carries a ``mode`` of ``"math"`` or ``"text"``. |
| `form` | dict[str, Any] | The syntactic form the slot takes; a dict with a ``type`` field, one of the ``ArgSpecFormType`` values. A ``paired`` form carries a ``pairs`` list of open/close delimiter descriptors. |

- [ValidateArgspecResult](https://texform.dev/api/python/validate-argspec.md#ValidateArgspecResult)

## `ArgSpecKindType`

Kind: typeAlias

```python
Literal['content', 'operatorname', 'delimiter', 'csname', 'dimension', 'integer', 'keyval', 'column', 'star']
```

Value kind of one parsed argspec slot (content, delimiter, star, ...).

## `ArgSpecFormType`

Kind: typeAlias

```python
Literal['standard', 'star', 'group', 'until', 'delimited', 'paired']
```

Surface form of one parsed argspec slot (mandatory, optional group, paired, ...).

