Skip to main content
Glama

Segment an image (SAM 2 / Grounded-SAM)

replicate_segment

Generate image segmentation masks from point, box, or text prompts using SAM 2 and Grounded-SAM, including automatic masks when no prompt is provided.

Instructions

Produce a segmentation mask of an image. Use SAM 2 for point/box-prompt masks (auto-mask everything when no prompt given) or Grounded-SAM for text-prompt masking like "the red car".

DISPLAY REQUIREMENT — embed the mask result inline using one of the three blocks printed by the tool.

Args:

  • image (URL): Source image.

  • prompt (string, optional): Text prompt for grounded segmentation. Required for grounded-sam.

  • model (default "sam-2"): Curated (sam-2, grounded-sam) or "owner/name".

  • extra_input (object, optional): SAM-specific tuning (e.g. {points_per_side: 32}).

Input Schema

NameRequiredDescriptionDefault
imageYesURL of the image to segment.
modelNoSegmentation model. Curated: sam-2, grounded-sam. Or "owner/name".sam-2
promptNoText-prompt for grounded segmentation (e.g. 'the red car'). Required for grounded-sam.
downloadNo
timeout_msNoMax ms to wait for the prediction. If exceeded, returns the prediction ID so you can poll via replicate_get_prediction. Default: 300000 (5min).
extra_inputNoModel-specific extras (e.g. {points_per_side: 32} for SAM 2 auto-mask).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv3.3.1
    • addedInput schema / properties / extra_input / propertyNames
      Added value: +{
      +  "type": "string"
      +}
  2. First observedv3.2.3

TDQS

A3.8/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnly=false, destructive=false, openWorld=true, idempotent=false, so the safety profile is covered. The description adds genuinely non-schema behavior: a mandatory DISPLAY REQUIREMENT to embed the mask inline via the tool's returned blocks, plus the promptless-auto-mask fallback. It omits what download=false does and any note on cost/latency, keeping it below a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose and mode routing, then the display requirement, then args. It is efficient overall, though the Args block largely duplicates schema descriptions that are already 83% covered, making it mildly redundant rather than harmful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

This is a 6-parameter, nested-object tool with no output schema, so the description must carry return-value burden. The phrase 'the three blocks printed by the tool' is left unexplained, and the download/polling behavior described in the schema is not surfaced, leaving gaps an agent must discover by calling.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 83%, so the schema already documents image, prompt, model, timeout_ms and extra_input. The description restates image/prompt/model/extra_input and adds a concrete extra_input example ({points_per_side: 32}) and the grounded-sam prompt requirement, but ignores download and timeout_ms entirely — baseline 3 fits when the schema carries the load.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Produce a segmentation mask of an image') and explains the two operating modes: SAM 2 for point/box-prompt or promptless auto-masking, Grounded-SAM for text prompts. It does not differentiate from adjacent siblings such as replicate_remove_background or replicate_inpaint, which an agent could plausibly confuse with segmentation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives explicit conditions for choosing between the two model modes ('Use SAM 2 for point/box-prompt masks ... or Grounded-SAM for text-prompt masking') and notes auto-mask-everything when no prompt is supplied. It stops short of when-not-to-use guidance versus sibling image tools or cost/prerequisite notes.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.