Mirrowel commited on
Commit
740e192
Β·
1 Parent(s): cfa8697

fix(antigravity): πŸ› preserve property names matching validation keywords

Browse files

Fix schema cleaning to preserve user-defined property names that coincidentally match JSON Schema validation keywords. Previously, properties named "pattern", "format", or "default" would be incorrectly removed.

- Separate meta/structural keywords from validation keywords
- Preserve property names in "properties" objects even when matching validation keywords
- Add debug logging for property names that match validation keywords

src/rotator_library/providers/antigravity_provider.py CHANGED
@@ -398,18 +398,37 @@ def _inline_schema_refs(schema: Dict[str, Any]) -> Dict[str, Any]:
398
  def _clean_claude_schema(schema: Any) -> Any:
399
  """
400
  Recursively clean JSON Schema for Antigravity/Google's Proto-based API.
401
- - Removes unsupported fields ($schema, additionalProperties, etc.)
 
 
 
 
402
  - Converts 'const' to 'enum' with single value (supported equivalent)
403
  - Converts 'anyOf'/'oneOf' to the first option (Claude doesn't support these)
404
  """
405
  if not isinstance(schema, dict):
406
  return schema
407
 
408
- # Fields not supported by Antigravity/Google's Proto-based API
409
- # Note: Claude via Antigravity rejects JSON Schema draft 2020-12 validation keywords
410
- incompatible = {
411
  "$schema",
 
 
 
 
412
  "additionalProperties",
 
 
 
 
 
 
 
 
 
 
 
413
  "minItems",
414
  "maxItems",
415
  "pattern",
@@ -432,10 +451,6 @@ def _clean_claude_schema(schema: Any) -> Any:
432
  "readOnly",
433
  "writeOnly",
434
  "examples",
435
- "$id",
436
- "$ref",
437
- "$defs",
438
- "definitions",
439
  "title",
440
  }
441
 
@@ -458,9 +473,29 @@ def _clean_claude_schema(schema: Any) -> Any:
458
  cleaned["enum"] = [const_value]
459
 
460
  for key, value in schema.items():
461
- if key in incompatible or key == "const":
 
 
 
 
 
462
  continue
463
- if isinstance(value, dict):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
  cleaned[key] = _clean_claude_schema(value)
465
  elif isinstance(value, list):
466
  cleaned[key] = [
 
398
  def _clean_claude_schema(schema: Any) -> Any:
399
  """
400
  Recursively clean JSON Schema for Antigravity/Google's Proto-based API.
401
+
402
+ Context-aware cleaning:
403
+ - Removes unsupported validation keywords at schema-definition level
404
+ - Preserves property NAMES even if they match validation keyword names
405
+ (e.g., a tool parameter named "pattern" is preserved)
406
  - Converts 'const' to 'enum' with single value (supported equivalent)
407
  - Converts 'anyOf'/'oneOf' to the first option (Claude doesn't support these)
408
  """
409
  if not isinstance(schema, dict):
410
  return schema
411
 
412
+ # Meta/structural keywords - always remove regardless of context
413
+ # These are JSON Schema infrastructure, never valid property names
414
+ meta_keywords = {
415
  "$schema",
416
+ "$id",
417
+ "$ref",
418
+ "$defs",
419
+ "definitions",
420
  "additionalProperties",
421
+ }
422
+
423
+ # Validation keywords - only remove at schema-definition level,
424
+ # NOT when they appear as property names under "properties"
425
+ # Note: These are common property names that could be used by tools:
426
+ # - "pattern" (glob, grep, regex tools)
427
+ # - "format" (export, date/time tools)
428
+ # - "default" (config tools)
429
+ # - "title" (document tools)
430
+ # - "minimum"/"maximum" (range tools)
431
+ validation_keywords = {
432
  "minItems",
433
  "maxItems",
434
  "pattern",
 
451
  "readOnly",
452
  "writeOnly",
453
  "examples",
 
 
 
 
454
  "title",
455
  }
456
 
 
473
  cleaned["enum"] = [const_value]
474
 
475
  for key, value in schema.items():
476
+ # Always skip meta keywords and "const" (already handled above)
477
+ if key in meta_keywords or key == "const":
478
+ continue
479
+
480
+ # Skip validation keywords at schema level (these are constraints, not data)
481
+ if key in validation_keywords:
482
  continue
483
+
484
+ # Special handling for "properties" - preserve property NAMES
485
+ # The keys inside "properties" are user-defined property names, not schema keywords
486
+ # We must preserve them even if they match validation keyword names
487
+ if key == "properties" and isinstance(value, dict):
488
+ cleaned_props = {}
489
+ for prop_name, prop_schema in value.items():
490
+ # Log warning if property name matches a validation keyword
491
+ # This helps debug potential issues where the old code would have dropped it
492
+ if prop_name in validation_keywords:
493
+ lib_logger.debug(
494
+ f"[Schema] Preserving property '{prop_name}' (matches validation keyword name)"
495
+ )
496
+ cleaned_props[prop_name] = _clean_claude_schema(prop_schema)
497
+ cleaned[key] = cleaned_props
498
+ elif isinstance(value, dict):
499
  cleaned[key] = _clean_claude_schema(value)
500
  elif isinstance(value, list):
501
  cleaned[key] = [