All jobs

Add Structured Data (JSON-LD) to a SvelteKit App

Yes. An agent adds Article, Person and WebSite JSON-LD to your SvelteKit app from the data its load functions already return, checks the built HTML and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the app and finds the pages are server-rendered, which is what makes structured data worth adding. In an app shaped like sveltejs/realworld, package.json pins SvelteKit ^2.52.2, Svelte ^5.55.7 with runes: true in svelte.config.js, adapter-vercel, marked and sanitize-html, with packageManager set to pnpm@10.20.0 and .nvmrc at Node 20. There is no test script; lint runs prettier --check .. src/hooks.server.js reads the jwt cookie into locals.user, src/routes/+layout.server.js passes a trimmed user to every page, and src/routes/article/[slug]/+page.server.js loads the article and its comments from api.realworld.show in one Promise.all, renders the body with marked and sanitizes it before returning { article, comments }. src/routes/profile/@[user]/+layout.server.js loads the profile the same way.

It then reads every <svelte:head>. The article page sets only <title>{data.article.title}</title>; the profile layout sets {username} • Conduit; the home page sets Conduit; the root layout adds the favicon. src/app.html carries the viewport, the manifest link and the theme stylesheet, static/robots.txt allows every crawler, and static/manifest.json names the app Svelte RealWorld. Nothing emits a meta description, a canonical link or JSON-LD. The article object the API returns already has what an Article needs: title, description, createdAt, updatedAt, tagList and an author with username, image and bio, the fields ArticleMeta.svelte and ArticlePreview.svelte render.

The change is one component and three heads. src/lib/JsonLd.svelte takes an object, serializes it with JSON.stringify and escapes < as \u003c before rendering it inside <svelte:head> with {@html} in a <script type="application/ld+json">, because titles and bios are user content from the API and a </script> inside them would otherwise end the tag. The article page emits an Article with headline, description, datePublished and dateModified from createdAt and updatedAt, keywords from tagList, mainEntityOfPage from page.url and an author Person whose url is /profile/@username, and gains the meta description it was missing. The profile layout emits a ProfilePage with a Person built from username, image and bio. The home page emits a WebSite named Conduit with the origin from page.url. The agent reads page from $app/state as Nav.svelte and +error.svelte already do, and leaves the home page's $app/stores import as it found it.

With no test suite to extend, the proof is the built HTML. The agent runs pnpm install, pnpm build and pnpm preview, fetches an article page, a profile and the home page with curl, cuts the ld+json script out of each and parses it with node to show it is valid JSON with the expected @type, then renders the component with a title containing </script> to show the escape holds. It finishes with pnpm lint, which is prettier with prettier-plugin-svelte, so the pull request is formatted the way the repository checks.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add structured data to this SvelteKit app. Read package.json, svelte.config.js, src/app.html, src/hooks.server.js, src/routes/+layout.svelte, +layout.server.js, +page.svelte and +page.server.js, src/routes/article/[slug]/+page.svelte, +page.server.js and ArticleMeta.svelte, src/routes/profile/@[user]/+layout.svelte and +layout.server.js, src/lib/api.js and the static directory first, and note every svelte:head already present. Add a small component that renders an object as a JSON-LD script inside svelte:head with < escaped so user content cannot close the tag. Emit an Article on the article page from title, description, createdAt, updatedAt, tagList and author, a ProfilePage with a Person on the profile layout, and a WebSite on the home page, using page.url for the URLs and adding the missing meta description on the article page. Do not add dependencies or change load functions. Build the app, serve it with the preview server, fetch each page with curl, extract and parse each ld+json block with node, show the escaping with a title that contains a closing script tag, run the lint script, and open a pull request that quotes the fetched blocks and the parse results.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds src/lib/JsonLd.svelte and changes src/routes/article/[slug]/+page.svelte, src/routes/profile/@[user]/+layout.svelte and src/routes/+page.svelte. No load function changes, because every field the markup needs is already returned, and no dependency is added.

The description shows the three ld+json blocks as fetched from the preview server, the node parse of each, and the escaped output for a title that contains a closing script tag. It names the schema.org types used and which API field feeds each property, so a reviewer can check the mapping without opening the files.

Before merging, a reviewer decides whether the author url should point at the profile route or at an external site, whether the WebSite block belongs in the root layout so every page carries it, and whether to add Open Graph tags in the same heads now that they are being touched. Each is a follow-up on the same session.

Run it on every content site indexed without JSON-LD

This is a change to start from the terminal and read later: one POST /o/{org}/sessions with this prompt and the repository in resources. The run reads the heads, writes the component, builds the site and reads the markup back before it opens the pull request. The sandbox parks with its disk when the turn ends, so a follow-up such as add BreadcrumbList to the article page wakes it with the build and node_modules still there.

A team with several SvelteKit sites sends the same body once per repository, one run each, and each run finds that site's own load functions and heads. Give the API key a webhook_url and Rush posts run.completed or run.failed with the session_url when each turn ends, so the pull request links arrive in one place. Send a request_id with each body so a retried POST does not start a second run.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Structured data is checked by crawlers, not by tests, so the only honest proof is the HTML a real build serves. The agent builds the app, starts the preview server and reads the markup back, and the pull request shows what a crawler will see, including the escaping that keeps a user-written title from breaking the page.

The run's record keeps the build output and every fetch, so a reviewer can see that the ld+json block is present on server render and not only after hydration, which matters for crawlers that do not run scripts. The sandbox parks after the turn, so adding Open Graph tags or a BreadcrumbList is a short follow-up that reuses the same build.

Frequently asked questions

Is the JSON-LD there on the first response, or only after hydration?

On the first response. The article, profile and home pages load their data in server load functions, so svelte:head renders the script during server-side rendering, and the curl fetches in the pull request show it in the raw HTML.

Why escape the JSON before rendering it with {@html}?

Because titles, descriptions and bios come from users through the API. JSON.stringify does not escape <, so a closing script tag inside a title would end the block and run what follows. Replacing < with its unicode escape keeps the JSON valid and the page safe.

Why not use a SvelteKit SEO package?

The data is already in the load functions and the markup is a dozen lines, so a dependency would add more than it saves. If you prefer a package, say so in a follow-up and the agent swaps the component for it.

Does it change the page titles?

No. The existing titles stay. The agent only adds the ld+json script and, on the article page, the meta description that was missing.

How do I check the result myself?

Open an article, view the page source and look for the ld+json script, or paste the URL into a rich-results testing tool. The pull request shows the same block as curl fetched it from the preview server.

More SvelteKit jobs

The same job on other stacks

Keep reading