When designing configuration systems, prefer semantic parameters over generic key-value approaches for common features, and implement runtime validation to detect incompatible configuration combinations.
When designing configuration systems, prefer semantic parameters over generic key-value approaches for common features, and implement runtime validation to detect incompatible configuration combinations.
For common functionality, use dedicated semantic variables rather than generic context variables. This maintains a unified API surface and prevents users from needing to learn template-specific idiosyncrasies. When features are incompatible, validate configurations at runtime and provide clear error messages.
Example:
// Good: Semantic parameter for common feature
struct config {
bool enable_thinking = true;
bool assistant_prefill = false;
};
// Validation with clear error message
if ((!inputs.enable_thinking) || inputs.chat_template_kwargs.find("enable_thinking") != inputs.chat_template_kwargs.end()) {
throw std::runtime_error("Assistant response prefill is incompatible with enable_thinking.");
}
This approach reduces complexity for users while maintaining flexibility for advanced use cases, and prevents runtime failures through proactive validation.
Enter the URL of a public GitHub repository