https://www.boundaryml.com logo
🟡 BAML Client: HTTP or CLI Subprocess Capability?
# questions
a
Hey, is a BAML `client`strictly an HTTP provider, or can it invoke CLI subprocess (e.g. claude -p / codex exec) (and subsequently parse to a structured output)? If clients are HTTP-only: is there a supported way to run just the BAML's schema-aligned parser on a string I already have?
a
in current version they are unfortunately strictly HTTP. to get claude code as a provider you can do a hack like this by abusing our modular API:
Copy code
ts
//baml_src/extract.baml
class Resume {
  name string
  skills string[]
}

function ExtractResume(resume_text: string) -> Resume {
  client Dummy
  prompt #"
    Extract the resume below.
    {{ resume_text }}
    {{ ctx.output_format }}   "#
}

client<llm> Dummy {
  provider openai-generic
  options { base_url "http://localhost:9/v1" model "x" api_key "x" }
}
Copy code
py
# main.py
import subprocess
from baml_client.sync_client import b

# 1. Render prompt (task + schema) — no network call, just to get ctx.output_format
req = b.request.ExtractResume("Jane Doe — Rust, Python, K8s")

# steal ctx.output_format from the BAML prompt
prompt = "\n".join(m["content"] for m in req.body.json()["messages"])

# 2. Run the CLI as the "model"
raw = subprocess.run(["claude", "-p", prompt], capture_output=True, text=True).stdout

# 3. Schema-aligned parse into the typed Resume
resume = b.parse.ExtractResume(raw)

print(resume.model_dump_json(indent=2))
we're cooking up a solution to this internally for the new compiler and this will be a first class feature once that lands!
if you want to hear about and try out the new compiler we do a weekly onboarding call, details here: https://luma.com/baml-eap
we'd love feedback!
a
this looks for my task, thanks!
2 Views