Repository navigation
Strict JSON and cancellation boundaries for preview-only LangChainGo tools #1601
aistudio12
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Maintainer disclosure: I represent SocialMediaScraper. This is an original AI-assisted application example using LangChainGo, with source and tests rather than a proposed framework change.
A
tools.Toolimplementation receives a string. Even if the model is told to emit JSON, a planner still needs to decide what to do with duplicate names, unknown fields,null, trailing objects and cancellation. I made a small preview-only adapter to make those boundaries concrete.Actual interface, fixed operations
The example imports the real
github.com/tmc/langchaingo/toolspackage atv0.1.15.Newreturnstools.Tool, with a compile-time interface assertion. A tool is created for one operation; caller JSON cannot choose a different operation or an HTTP origin.The underlying package is the already published
github.com/aistudio12/socialmediascraper-go-planner v0.1.0. Four tools cover narrow request-plan inputs for YouTube profile, Instagram profile, TikTok profile and Reddit search. This is four selected GET operations, not our separate MCP adapter's 197-operation catalog or a full OpenAPI executor.Try the example
Use Go 1.24.4 or later. After reviewing and downloading the complete example source, from that directory:
go mod tidy go test -race -count=1 -v ./... go vet ./...Module setup downloads dependencies. The preview calls need no provider account, API key, model key or environment configuration.
ExampleNewis a runnable Go example test. It creates the YouTube tool and calls the actual SDK interface with a synthetic JSON object:{"channel_id":"UC_SYNTHETIC_EXAMPLE","idempotency_key":"synthetic-example-001"}The result is request metadata with
"request_sent": falseand a nestedplan: operation ID, method, URL, non-secret headers and snapshot version. It is not a provider response or fetched audience data. Reports contain supplied identifiers and search text, so keep inputs synthetic and non-sensitive.What the boundary checks
Before generating a plan, the adapter requires one flat JSON object, limits UTF-8 input to 16 KiB and rejects invalid UTF-8. It rejects repeated top-level field names, including escaped aliases such as
handleand\u0068andle. Exact allowlists reject unknown fields and Go JSON's otherwise convenient case aliases, soHandledoes not silently becomehandle.Nulls and incorrect field types are rejected instead of being coerced into zero values. Instagram retains a supplied
false; Unicode and query delimiters go through the base planner's query encoder. Each call checks its context before parsing and before returning its plan. The example also exercises concurrent use of one immutable tool instance with the race detector.The accepted objects are deliberately flat and narrow. This is not a recursive JSON validation library. It does not implement every optional parameter of the base package, an agent loop, callback reporting, structured model selection or an MCP transport. Validation errors return no plan and avoid echoing rejected payload values. Fix the inputs rather than blindly retrying them.
Observed verification
The public Ubuntu / Go 1.27.4 workflow compiled a race-enabled test binary using the real pinned modules, then ran that binary with
sudo unshare --net. Four top-level tests, twenty nested cases and one Go example passed, followed byNETWORK_NAMESPACE_CHECKS_OK. Dependency resolution happened earlier with network access; the test binary ran without an external network interface. This does not count attempted connections or establish a production sandbox. The preserved build artifact contains the same two Go source files plus the exact resolvedgo.modandgo.sum, which are included with the example. GitHub also reported a Node20-action migration warning.Fees, versions and untested behavior
The MIT preview software is free. Executing a real social-data request is a separate paid action with a customer's own authorized, funded provider account. This adapter has no execution method, HTTP client, key input, pagination or retry loop, and no account-wide spending cap.
The input subset is dated. A matching API version label does not establish that live headers or parameters are identical. Review the current OpenAPI, including authentication, idempotency and optional
x-price-version, before separately implementing execution. This adapter leaves that optional header unset and does not predict current charges.No LLM, hosted MCP/OAuth, remote dataset or paid provider response is tested. This is an application example; it is not a maintainer-approved LangChainGo integration. The 20 task guides describe the broader research use cases and limits.
All reactions