Strip a model string; treat blanks as unset; reject unsafe values. Mirrors ``_coerce_language``. The model string is passed to LiteLLM and also echoed in logs/CLI output, so embedded control characters would corrupt that output. Capping length keeps pathological values out of config
(value: str | None)
| 846 | |
| 847 | |
| 848 | def _coerce_model(value: str | None) -> str | None: |
| 849 | """Strip a model string; treat blanks as unset; reject unsafe values. |
| 850 | |
| 851 | Mirrors ``_coerce_language``. The model string is passed to LiteLLM and |
| 852 | also echoed in logs/CLI output, so embedded control characters would |
| 853 | corrupt that output. Capping length keeps pathological values out of |
| 854 | config.yaml. |
| 855 | |
| 856 | Returns the cleaned string, or ``None`` if the input was missing or blank |
| 857 | after stripping. Raises ``click.BadParameter`` on unsafe input. |
| 858 | """ |
| 859 | if value is None: |
| 860 | return None |
| 861 | value = value.strip() |
| 862 | if not value: |
| 863 | return None |
| 864 | if len(value) > _MODEL_MAX_LEN or any(c in value for c in "\n\r\t"): |
| 865 | raise click.BadParameter( |
| 866 | f"model must be {_MODEL_MAX_LEN} characters or fewer with no control characters", |
| 867 | param_hint="'--model'", |
| 868 | ) |
| 869 | return value |
| 870 | |
| 871 | |
| 872 | def _model_option_callback(_ctx, _param, value): |
no outgoing calls
no test coverage detected