Skip to content

Modernize field!/sign!/hashmap! macros to emit typed SignatureSchema #73

Open

Description

@darinkishore

Context

lib.rs defines three macros:

  • field! (lines 46-133) — generates serde_json::Value maps via schemars. Only used in tests/test_field_macro.rs.
  • sign! (lines 135-171) — inline signature + Predict creation. Zero callers currently.
  • hashmap! (lines 178-187) — convenience HashMap literal. Used in tests/examples.

These are ergonomic features for the untyped path. field! and sign! use schemars::schema_for!() to generate JSON schemas, which is the pre-V1 approach. The typed path uses #[derive(Signature)] + SignatureSchema::of::<S>().

What's needed

field! macro

  • Should emit typed FieldSchema values instead of serde_json::Value maps
  • Or consider if #[derive(Signature)] makes this macro redundant

sign! macro

  • Should work with the typed Signature derive and produce a Predict<__InlineSignature> that's fully wired (accessor registration, etc.)
  • Currently generates a derive but doesn't call register_predict_accessor or build()

hashmap! macro

  • Low priority. HashMap::from([...]) is standard Rust. Keep or kill, doesn't matter much.

schemars dependency

  • __macro_support re-exports schemars solely for field!
  • Once field! is modernized, schemars can be dropped from Cargo.toml (also requires specials.rs migration, see related issue)

Related

Activity

  1. darinkishore commented on Feb 12, 2026

    @darinkishore
    CollaboratorAuthor

    Codebase audit — current macro state

    field! (lib.rs:148-236):

    • Emits serde_json::Value objects via schemars::schema_for!()
    • Only caller: tests/test_field_macro.rs
    • Useful ergonomic: declare fields inline without a full #[derive(Signature)] struct

    sign! (lib.rs:238-274):

    • Creates an anonymous __InlineSignature struct with #[derive(Signature)] and returns Predict::<__InlineSignature>::new()
    • Zero callers currently
    • Would be great for quick prototyping: let p = sign!((question: String) -> answer: String);

    hashmap! (lib.rs:276-290):

    • Standard convenience macro. Works fine, no changes needed.

    Modernization path for field!:

    • Should emit FieldSchema (from core/schema.rs) instead of serde_json::Value
    • Use facet::Shape or BamlType::baml_type_ir() instead of schemars::schema_for!()
    • Example new output:
      field! { input["Description"] => question: String }
      // → FieldSchema { name: "question", description: "Description", type_ir: String::baml_type_ir(), ... }

    Modernization path for sign!:

    • Currently works since it does #[derive(Signature)] — but it doesn't call register_predict_accessor or wire up the builder pattern
    • Should produce a fully functional Predict that works with optimizers
    • Consider if this needs to produce a named type (for optimizer walker to find) or if anonymous is fine for non-optimized use

    schemars removal: once field! uses BamlType::baml_type_ir() instead of schemars::schema_for!(), the schemars dep in __macro_support and Cargo.toml can be dropped (assuming #72 is also done).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions