Skip to content

Commit

Permalink
fix: reject grammars without properties (huggingface#2309)
Browse files Browse the repository at this point in the history
  • Loading branch information
drbh authored and yuanwu2017 committed Sep 25, 2024
1 parent 23a3927 commit a574381
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions router/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ impl Validation {
.compile(&json)
.map_err(|e| ValidationError::InvalidGrammar(e.to_string()))?;

// The schema can be valid but lack properties.
// We need properties for the grammar to be successfully parsed in Python.
// Therefore, we must check and throw an error if properties are missing.
json.get("properties")
.ok_or(ValidationError::InvalidGrammar(
"Grammar must have a 'properties' field".to_string(),
))?;

// Serialize json to string
ValidGrammar::Json(
serde_json::to_string(&json)
Expand Down

0 comments on commit a574381

Please sign in to comment.