Skip to content

fix(tools): canonical JSON Schema for chat tools#232

Merged
chubes4 merged 1 commit into
mainfrom
fix-canonical-tool-schemas
May 9, 2026
Merged

fix(tools): canonical JSON Schema for chat tools#232
chubes4 merged 1 commit into
mainfrom
fix-canonical-tool-schemas

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented May 9, 2026

Why

Data Machine 0.106.1 PR #1900 ("Require canonical AI tool schemas") removes the auto-normalization layer in RequestBuilder::normalizeToolParameters that previously converted legacy property-keyed parameter shapes into canonical JSON Schema on the way to providers. Extension plugins must now ship canonical schemas directly.

This is a pre-flight fix landed before the DM bump — canonical schemas already work on DM 0.103.14 (current production on extrachill.com), so this PR can ship and deploy independently of the DM upgrade.

What changed

Converted all 9 chat tool definitions in inc/Api/Chat/Tools/ from the legacy shape:

// Legacy
'parameters' => array(
    'venue' => array( 'type' => 'string', 'required' => true, 'description' => '...' ),
)

…to canonical JSON Schema:

// Canonical
'parameters' => array(
    'type'       => 'object',
    'properties' => array(
        'venue' => array( 'type' => 'string', 'description' => '...' ),
    ),
    'required'   => array( 'venue' ),
)

Files

  • inc/Api/Chat/Tools/EventHealthCheck.php
  • inc/Api/Chat/Tools/EventQualityAudit.php
  • inc/Api/Chat/Tools/FindBrokenTimezoneEvents.php
  • inc/Api/Chat/Tools/FixEventTimezone.php
  • inc/Api/Chat/Tools/GetVenueEvents.php
  • inc/Api/Chat/Tools/TestEventScraper.php
  • inc/Api/Chat/Tools/UpdateEvent.php
  • inc/Api/Chat/Tools/UpdateVenue.php
  • inc/Api/Chat/Tools/VenueHealthCheck.php

The original task scoped this to 6 files. The remaining 3 (EventHealthCheck, FindBrokenTimezoneEvents, GetVenueEvents) had identical legacy shapes and would have broken on DM 0.106.1 too — converting all 9 in one PR makes the pre-flight actually pre-flight.

Conversion rules applied

  1. Wrap properties under { type: 'object', properties: {...} }.
  2. Move required => true properties into a top-level required[] array of property names; remove required from individual property defs.
  3. Drop required => false entirely (it was a no-op).
  4. Omit required key when no properties are required (don't emit empty arrays).
  5. Every type: array property gains an items schema (required by OpenAI strict tool-schema validation, see MEMORY.md). Choices made:
    • FixEventTimezone.eventsitems: { type: object } (array of update structs)
    • UpdateEvent.eventsitems: { type: object } (array of update structs)
    • UpdateEvent.occurrenceDatesitems: { type: string } (array of YYYY-MM-DD date strings)
  6. All other property keys (description, enum) preserved verbatim.

Required fields summary

  • UpdateVenue: venue
  • TestEventScraper: target_url
  • GetVenueEvents: venue
  • All others have no required fields (optional-only schemas).

Out of scope (intentionally)

  • inc/Steps/Upsert/Events/EventUpsertFilters.php — verified. Its parameters array is built dynamically by merging output from EventSchemaProvider::getCoreToolParameters(), EventSchemaProvider::getSchemaToolParameters(), TaxonomyHandler::getTaxonomyToolParameters(), and VenueParameterProvider::getToolParameters(). Those provider methods still emit the legacy property-keyed shape, but the entry point is handler tool registration, not chat tools — different code path through Data Machine's pipeline engine. Worth a follow-up audit before DM 0.106.1 deploys, but separate from this PR.

Backwards compatibility

Canonical schemas are accepted by both DM 0.103.14 (current production) and DM 0.106.1+ (target). The legacy normalization path on 0.103.x silently passes canonical schemas through. No behavior change on the current site.

Test plan

  • PHP syntax check (php -l) passes on all 9 edited files.
  • homeboy lint --path . --changed-since main shows no findings on any of the 9 edited tool files (only pre-existing baseline noise in UniversalWebScraper.php and other unrelated files).
  • Verified converted schemas match the contract in DM 0.106.1 RequestBuilder::normalizeToolParameters passthrough path.
  • Live tool calls in production chat post-merge (manual sanity check on at least update_venue and event_quality_audit).

Constraints honored

  • Branched off main, no commits to main.
  • No CHANGELOG.md edits, no version constant bumps — homeboy owns those.
  • No deploy, no release.

Required by data-machine 0.106.1 PR #1900 which removes legacy schema
auto-normalization. Backwards compatible with 0.103.x.

Converts all 9 chat tool definitions from the legacy property-keyed
shape (with per-property 'required' booleans) to canonical JSON Schema:
parameters wrapped in { type: 'object', properties: {...}, required: [...] }.

Also adds 'items' schemas to every array property (required by OpenAI
strict tool-schema validation):
- FixEventTimezone.events: items=object
- UpdateEvent.events: items=object
- UpdateEvent.occurrenceDates: items=string

Files: EventHealthCheck, EventQualityAudit, FindBrokenTimezoneEvents,
FixEventTimezone, GetVenueEvents, TestEventScraper, UpdateEvent,
UpdateVenue, VenueHealthCheck.
@homeboy-ci
Copy link
Copy Markdown
Contributor

homeboy-ci Bot commented May 9, 2026

Homeboy Results — data-machine-events

Audit

audit — passed

  • dead_code — 9 finding(s)
  • test_coverage — 9 finding(s)
  • Total: 18 finding(s)

Deep dive: homeboy audit data-machine-events --changed-since e1f629a

Tooling versions
  • Homeboy CLI: homeboy 0.163.1+28edfdb
  • Extension: wordpress from https://github.com/Extra-Chill/homeboy-extensions
  • Extension revision: 56b5c09
  • Action: Extra-Chill/homeboy-action@v2

@chubes4 chubes4 merged commit 8e2c350 into main May 9, 2026
1 check passed
chubes4 added a commit that referenced this pull request May 9, 2026
Follow-up to PR #232. Converts the upsert_event handler tool
registration to emit a canonical JSON Schema (type: object,
properties, required) instead of a flat property bag.

Required for DM 0.106.1 compatibility. PR #1900 in data-machine
core makes RequestBuilder::normalizeToolParameters a passthrough,
so handler tool definitions must already be canonical when registered.

NOT backwards-compatible with DM 0.103.x at the provider return shape
level: EventSchemaProvider and VenueParameterProvider now return
canonical fragments ({properties, required?}) instead of flat
property bags. The handler tool wire-up (EventUpsertFilters) is the
only consumer of these providers in this plugin. No tests pin the
old shape.

TaxonomyHandler::getTaxonomyToolParameters() in data-machine core
still returns a flat property bag. EventUpsertFilters' composer
absorbs that shape transparently as a degenerate fragment with no
required fields, so this PR works regardless of when DM core
converts TaxonomyHandler to canonical fragments.

Changes:
- DynamicToolParametersTrait::filterByEngineData() now operates on
  canonical fragments and prunes filtered keys from both 'properties'
  and 'required'.
- EventSchemaProvider::fieldsToToolParameters() emits canonical
  fragments. Per-property 'required' booleans are aggregated into a
  top-level required[] array. 'required' key omitted when empty.
- VenueParameterProvider returns a canonical fragment with no
  required fields (venue presence is enforced upstream).
- EventUpsertFilters::getDynamicEventTool() composes fragments via
  new composeCanonicalParameters() helper. Tolerates both canonical
  fragment shape and legacy flat property bag from TaxonomyHandler.
- All array-typed properties carry an 'items' schema (already in
  source declarations; preserved through fieldsToToolParameters).

Co-authored-by: homeboy-ci[bot] <266378653+homeboy-ci[bot]@users.noreply.github.com>
chubes4 added a commit to Extra-Chill/extrachill-roadie that referenced this pull request May 9, 2026
DM 0.107.0 removes the auto-normalization layer that previously
converted legacy property-keyed parameter shapes. Convert all 4 chat
tool definitions in inc/tools/ to canonical JSON Schema directly:

- Wrap properties under { type: 'object', properties: {...} }
- Move required => true fields into top-level required[] array
- Drop required => false (no-op)
- Add items schema to every type: array property (OpenAI strict
  schema validation requires it)
- Preserve description and enum verbatim

Forward-compatible pre-flight: works on DM 0.103.14 (current
production) and DM 0.107.0+ (target). Same pattern as
Extra-Chill/data-machine-events#232.

Closes #5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant