feat(mcp): one check of every write tool's text for a tax id, from a table of its strings

Every string a write tool takes (423 across 78 tools) is classed in
text_fields::TABLE: 127 free text (refused when it looks like a tax id),
27 party fields (refused at any run of nine digits, as the engine does),
and 269 exempt for a named reason (vault input, lookup key, id, amount,
date, vocabulary, last four digits, bank pattern, link, a structured value
the engine reads). The check runs in call_tool before the tool or any
write, for previews too, and a refused call writes nothing (WB-format-10).
A test fails when a write tool has a string the table does not class, or
the table names one no tool takes. A string the table does not know is
free text. Annotations on a receipt (payee, source, note ...) meet the
engine's check as well.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 14:57:58 -07:00
1 parent 548901ce7d
commit 7327d04897
6 files changed
+1379 -1

No files matched your search

+16
View File
@@ -74,6 +74,19 @@ impl AnnotationFields {
self.category = trim(self.category);
self.source = trim(self.source);
self.reimbursable_to = trim(self.reimbursable_to);
// Who, what and where in words: no tax id among them (BS-partner-2;
// not in a replay, which keeps the journal as written).
for (field, text) in [
("the payee", &self.payee),
("the payment method", &self.instrument),
("the category", &self.category),
("the source", &self.source),
("who is to be reimbursed", &self.reimbursable_to),
] {
if let Some(t) = text {
LedgerError::free_text(field, t)?;
}
}
if self.receipt_number == Some(0) {
return Err(LedgerError::InvalidEvidence(
"a receipt number is positive".into(),
@@ -111,6 +124,9 @@ impl Annotation {
.note
.map(|n| n.trim().to_string())
.filter(|n| !n.is_empty());
if let Some(n) = &self.note {
LedgerError::free_text("the note", n)?;
}
if self.fields.is_empty() && self.note.is_none() {
return Err(LedgerError::InvalidEvidence(
"an annotation records at least one field or a note".into(),
+1 -1
View File
@@ -8755,7 +8755,7 @@ impl Ledger {
&mut self,
annotation: crate::evidence::Annotation,
) -> Result<(), LedgerError> {
self.annotate_attachment(annotation)
crate::parties::replaying(|| self.annotate_attachment(annotation))
}
/// The entries `entry` records settling (`entry.settles`, plan P6).
+3
View File
@@ -133,6 +133,9 @@ pub(crate) const STOPPED: &str = "stopped";
pub(crate) const STOPPED_BY_CLOSE: &str = "stopped_by_close";
/// A file's bytes or text came as an argument (D-46).
pub(crate) const INLINE_FILE: &str = "inline_file";
/// A call refused unrun because a string in it looks like a tax id
/// (text_fields.rs).
pub(crate) const TIN_IN_TEXT: &str = "tin_in_text";
/// What a refused call is told when its record couldn't be kept, or a
/// call that ran is told instead of its answer (INVARIANT 3).
+11
View File
@@ -1588,6 +1588,8 @@ mod next_steps;
mod projects;
#[path = "tools/prompts.rs"]
mod prompts;
#[path = "text_fields.rs"]
mod text_fields;
pub use kept::SettingKeyOut;
// The tool groups: one file each (plan/served.md 8.2 U0a). A unit adds a
@@ -1934,6 +1936,15 @@ impl ServerHandler for BooksServer {
}
calls::key_problem(request_key.as_ref())
.map(|why| (calls::MISSING_KEY, Ok(tool_error(why))))
})
// A string that looks like a tax id isn't run, whatever it was for:
// the vault is where one goes (text_fields.rs INVARIANT 5).
.or_else(|| {
if !calls::writes(&request.name) {
return None;
}
text_fields::refusal(&request.name, request.arguments.as_ref())
.map(|why| (access::TIN_IN_TEXT, Ok(tool_error(why))))
});
if let Some((code, answer)) = refusal {
call.digested(refused_digest(request.arguments.clone()).await);
+56
View File
@@ -1702,3 +1702,59 @@ fn the_envelope_keeps_what_a_tool_said_and_carries_a_refusal_guard() {
assert_eq!(g["code"], "approval_required");
assert_eq!(g["remedy_tool"], "books.approve_entry");
}
/// text_fields.rs INVARIANT 5 (WB-format-10): a call with a string that
/// looks like a tax id is refused before it runs, in words that name the
/// field and never repeat the number; the books are as they were and the
/// access record says why. A reference that is no tax id goes on to the tool.
#[test]
fn a_call_with_a_tax_id_in_free_text_is_refused_unrun_and_writes_nothing() {
rt().block_on(async {
let s = session("tin-text").await;
let (server, books) = logged("tin-text");
let key = "key-0123456789";
let add = |name: &str| {
tool_call(
"books.add_class",
serde_json::json!({"name": name, "request_key": key}),
)
};
let (refusal, text) = answer(
server
.call_tool(add("Rondo 000-00-0000"), context(&s.peer, Some(ALL)))
.await,
)
.unwrap();
assert!(refusal, "{text}");
assert!(
text.starts_with("the name of books.add_class looks like it holds a tax id"),
"{text}"
);
assert!(text.contains("books.set_tin") && text.contains("W-9"), "{text}");
assert!(!text.contains("000"), "never the number: {text}");
// A preview is refused too: its text would be shown to a person.
let draft = tool_call(
"books.draft_entry",
serde_json::json!({"date": "2026-11-21", "description": "pay 00-0000000", "request_key": key}),
);
let (refusal, text) =
answer(server.call_tool(draft, context(&s.peer, Some(ALL))).await).unwrap();
assert!(refusal && text.contains("the description of books.draft_entry"), "{text}");
// Nothing was made: no class, no entry.
let projects = tool_call("books.projects", serde_json::json!({}));
let (refusal, text) =
answer(server.call_tool(projects, context(&s.peer, Some(ALL))).await).unwrap();
assert!(!refusal && !text.contains("Rondo"), "{text}");
// A reference that is no tax id is not refused for being one.
let (_, text) = answer(
server
.call_tool(add("Rondo 2026-11-0042"), context(&s.peer, Some(ALL)))
.await,
)
.unwrap();
assert!(!text.contains("looks like it holds a tax id"), "{text}");
let log = records(&books);
assert_eq!(log[0], ("books.add_class".into(), refused("tin_in_text"), true));
assert_eq!(log[1], ("books.draft_entry".into(), refused("tin_in_text"), true));
});
}
File diff suppressed because it is too large. Load diff