Skip to Content
Recodocs

In a property marketplace the model writes the answer and the host enforces the checks

One model loop picks reads and phrases replies. Scope holds and quote fences are code; consent, comparison and save verdicts are a second model call the host enforces before a claim is shown.

8 min read

A recommendation depends on the constraints the customer actually needs. If the system cannot filter on a required property, asking for clarification or acknowledging the limitation is more useful than displaying results that fail the requirement.

A renter asks for offices in Noida with at least 1,000 square feet of carpet area. The model calls the rental recommender, and a check stops it: carpet suitability is not something the recommender can filter on. Nothing is searched. On the first turn the scripted reply is a clarification, inventory is not read, and the tool status is requirements_needed. Only when the renter says so, in words the system can quote back, does one search run, with the carpet clause still listed as unverified.

Another renter has Cedar House and Birch House on screen and asks to compare the first two displayed offers. For a plain "compare the first two displayed offers" request, the host performs the comparison read before the model is called; other comparison wording falls back to a model call pinned to that tool.

The claim is that a marketplace agent is trustworthy when the model owns wording and the choice among reads, and everything that carries consequence is held by separate checks: some are plain code (scope hold, quote fences), others are a second model call whose verdict the host enforces. The catalog holds source observations; there is no live reservation or completed purchase transaction.

The argument

  1. Scope is decided before a search runs. A requirement the catalog cannot enforce holds the search until the user accepts it in a quotable sentence. The hold and the quote fences are code; consent meaning is a second model call whose verdict the host enforces.
  2. A comparison is a receipt. For a plain "compare the first two displayed offers" request, the host performs the comparison read before the model is called; other comparison wording falls back to a model call pinned to that tool. A later checker is itself a model verdict.
  3. A save needs its own check. The write tools stay visible. A second model call reads the user's message and answers supported with the tool it allows, contradicted, or unverifiable; only supported with that exact tool admits the write.
  4. Tests state the guards, and none of them is a success rate. Two use a scripted model and two call the guard directly.

Who is allowed to decide

The tempting description of this service is one brain with database access. The code separates authorship from authority. One PydanticAI agent serves discovery, recommendations, comparisons, saved choices and enquiry drafts, and the design splits no further, because splitting one conversation into agents adds delegation and history costs. Around it, governance owns evidence, consent, receipts and budgets; the rental capability ranks the eligible set and then applies the limit.

Who owns each boundaryA customer question enters governed orchestration. Inside, governance admits scope and writes, the compose PydanticAI agent chooses among read tools, native checks validate output, and the catalog returns listing ids. Enquiry saves and preference writes stop outside the model loop without explicit consent.CustomerBearer sessionOne new messageper POST /v1/chatWrite refusedsave, mark preferredWithout WriteConsentCheckOrchestrationtravel_marketplaceGovernanceconsent, evidence, writescompose agenttool choice among readsnative_checksvalidators, retriesCatalog SQLranked observationsProduct DBdim_cities, fct_listingsHistorical observationsNot live reservationPydanticAI 2.2.0create_agent loopTool calls + final_resultoutput_validator hooksquestionanswerreadidsmodel
Governance and catalog sit outside model discretion; only read tools and phrasing sit inside the compose loop.

Read the figure from the outside in. The customer sends one new message per request. Governance sits first at the top of the stack, and it admits scope and writes. Only then does the compose agent work, choosing among read tools. Native checks, which are validators with retries, sit between the agent and the catalog. The catalog SQL at the bottom returns ranked observations as listing ids. The lower-left orange card is a save or preferred mark refused without WriteConsentCheck.

That path is pinned by a test. Asked to "Show the saved draft exactly," no write runs and nothing is changed. Asked to "Save this offer to my choices," the write tool is admitted only after the separate check returns the allowed tool, and then one mutation occurs. The check is a second model call. It reads the user's current message and answers supported with the tool it allows, contradicted, or unverifiable; only supported with that exact tool admits the write. The model's own reasoning text is kept out of what that check sees.

Ranking follows the same split. A deterministic recommender never relaxes the required city, and ranks the full eligible set before it applies the limit. Locality is a soft preference by default and can be required, which excludes other and unknown localities; city stays an AND constraint when supplied. The catalog records Delhi and New Delhi as different cities, and the agent does not get to decide they are the same. The model may call the recommender. It is not the policy.

Transport enforces the boundary too. A chat request accepts one new user message, and history sent by the browser is rejected, so the server's own transcript stays authoritative. Browser history is rejected, and a previous shortlist is not projected onto a later turn as current evidence.

What the evidence shows

"Grounded answers" is easy to say and hard to demonstrate. Four tests show four separate guards; two use a scripted model and two call the guard directly.

GuardWhat the test showsWhat it stops
Scope holdReads stay empty and status is requirements_needed until consent arrivesSearching on a partial reading of the request
Comparison checkA scripted checker returns contradicted on the first answer; the loop takes three model steps instead of twoA scripted contradicted verdict, followed by the host retry
Draft quote guardThe answer is corrected when it quotes the supplied message argument rather than the text the host storedA quote of the supplied message argument
Write consentZero mutations unless the check admits the writeA save the shopper did not ask for
Stay discovery held until quoted consentsearch_admitted_stays returns requirements_needed with unapplied guest and date clauses. No search_stay_properties call runs until partial_scope_acceptance carries the user quote on the current turn.Mandatory needsfour guests, dates, capstatus: requirements_neededreads == []search_admitted_staysuser_quoteScoped consentPartialScopeAcceptanceunverified: guest_capacitylen(reads) == 1archived_property_discoveryHotelsMumbai limit 3
Unsupported stay predicates stay held until the user's quote matches the current turn.

The figure shows the first row. On the left, four mandatory needs arrive: four guests, one private room, dates and a nightly cap. The card is labeled four guests, dates, cap. The status is requirements_needed and the orange line reads reads == []. On the right, after the quoted acceptance, one stay read runs for hotels in Mumbai with limit 3, and guest capacity stays unverified. Consent does not turn an unverified need into a verified one. It only permits a search that admits what it cannot check. A changed profile, a changed catalog or an intervening read invalidates the quote, so a stale acceptance cannot reopen inventory.

The comparison check shows the second row. A scripted checker returns contradicted on the first answer; the host sends a retry prompt naming the comparison and listings, and the loop takes three model steps instead of two. When that scripted checker does not mark the answer contradicted, the loop takes two model steps. Display order and comparison order are tracked separately, so reversing a comparison does not rewrite which offer was shown first. The draft-quote guard corrects an answer when it quotes the supplied message argument rather than the text the host stored.

Citations work the same way at the id level. Ordinary answer ids are grounded against historical tool observations; the latest recommend_rentals return after the latest user prompt controls current recommendation ids. An older successful search cannot silently become active again.

None of this is a satisfaction score. What would falsify the claim is an accepted answer that cites a listing no tool returned on that turn, or a saved choice with no completed consent check. Shared-database, browser, and real-model acceptance still need observed evidence and existing authorization.

The turn we exercised

The comparison turn shows the host and the model sharing a turn without blending roles. The history already holds a recommendation that returned Cedar House and Birch House. The test then runs the agent on "Compare the first two displayed offers." Product hooks, toolsets, validators and the comparison read are real. The model, the catalog rows and the usage accounting are fixtures.

Comparison before the first provider requestAfter rentals are accepted, the host injects a compare_offers tool return with a host-routed call id. The model first provider request already includes that receipt; only the answer step bills usage.Historyrecommend_rentalsDisplayed Cedar, BirchHost routecompare_offersNo provider usageModel oncefinal_resultComparison proseAcceptvalidatorslisting_ids kepttest_resolved_comparison_reads_without_provider_request_then_answers fixes this ordering.
compare_offers is host-routed; the model does not choose that read on turn one.

Follow the four boxes. The history holds the two displayed listings. For this plain displayed-offers wording, the host route performs the comparison read with no provider usage, and inserts the result as a tool return. The model then runs once to write the comparison. The validators accept the answer and keep the listing ids. The assertions pin each step. Before the answer request there is exactly one comparison receipt, and its call id carries the host-routed prefix. Only one answer request from the agent reaches the model; the validator's verdict check is a separate call. The routed step has no model name and no provider response id, and the public activity lists one model step, not two. In this turn the model is not offered a forced choice of the comparison tool.

This matters for accounting as well as safety. Two response records exist in that turn, but only one cost money. A usage dashboard that counted them as two model calls would be wrong. The routed step carries no model name and no provider response id.

Agent-loop tests cover the held first turn (no read, clarification) and, separately, a consent turn where a scripted check verdict releases one search; declarations not found verbatim in the user's words are rejected by the tool's own validation.

The one check to copy

Copy the comparison receipt, not the property nouns. For a plain "compare the first two displayed offers" request, the host performs the read and puts the result in the history before the first provider request. Other comparison wording falls back to a model call pinned to that tool. On the host-routed path the model sees the receipt. In this turn it is not offered a forced choice of the comparison tool. The assertions that keep this honest are:

receipts = [p for m in messages for p in m.parts
            if isinstance(p, ToolReturnPart) and p.tool_name == 'compare_offers']
assert len(receipts) == 1, 'The comparison read must precede the first provider request.'
assert receipts[0].tool_call_id.startswith(compose.HOST_ROUTED_CALL_PREFIX)
assert len(agent_requests) == 1, 'Only the answer request may reach the provider.'

The pattern repeats across the service. A stay holds until quoted consent. A write waits for the check that admits it. The answer is corrected when it quotes the supplied message argument rather than the text the host stored. Each pairs a claim the model would like to make with evidence the host can check. To port the host-routed comparison, put that read ahead of the provider only for the plain displayed-offers wording, and leave other wording on the pinned tool call.

Close

A property marketplace invites the story of an LLM with database tools. The tests describe a tighter system. The model chooses among reads it is given and writes the reply. Governance decides whether a search may run, which ids count as evidence, and whether a save may execute, and it enforces the comparison verdict. Validators return bad output to the model rather than ship it.

Extend this by adding a write only with a consent check and a test that proves its absence otherwise. Extend discovery only with a hold and a test that reads stay empty. Extend the plain displayed-offers comparison only with a host read that arrives before the provider does; other comparison wording stays a model call pinned to that tool. The catalog remains a record of observations, and treating it as live inventory would break the service's own boundary.

How is this page?

Last updated on