diff --git a/lib/modules/manager/pep621/utils.ts b/lib/modules/manager/pep621/utils.ts
index a53f9530805cae81204785e7b44b15cdf06870a5..178239a0651e88f4f7c05c58949445047c691166 100644
--- a/lib/modules/manager/pep621/utils.ts
+++ b/lib/modules/manager/pep621/utils.ts
@@ -1,8 +1,7 @@
 import is from '@sindresorhus/is';
 import { logger } from '../../../logger';
 import { regEx } from '../../../util/regex';
-import { stripTemplates } from '../../../util/string';
-import { parse as parseToml } from '../../../util/toml';
+import { massage as massageToml, parse as parseToml } from '../../../util/toml';
 import { PypiDatasource } from '../../datasource/pypi';
 import { normalizePythonDepName } from '../../datasource/pypi/common';
 import type { PackageDependency } from '../types';
@@ -137,7 +136,7 @@ export function parsePyProject(
   content: string,
 ): PyProject | null {
   try {
-    const jsonMap = parseToml(stripTemplates(content));
+    const jsonMap = parseToml(massageToml(content));
     return PyProjectSchema.parse(jsonMap);
   } catch (err) {
     logger.debug(
diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts
index d75a66934438a3a809c99a1cbebfe5e60f1a4f07..6e1b2b5aae65944e04918a0fc91eca899db45861 100644
--- a/lib/modules/manager/poetry/artifacts.ts
+++ b/lib/modules/manager/poetry/artifacts.ts
@@ -16,8 +16,7 @@ import { getGitEnvironmentVariables } from '../../../util/git/auth';
 import { find } from '../../../util/host-rules';
 import { regEx } from '../../../util/regex';
 import { Result } from '../../../util/result';
-import { stripTemplates } from '../../../util/string';
-import { parse as parseToml } from '../../../util/toml';
+import { massage as massageToml, parse as parseToml } from '../../../util/toml';
 import { parseUrl } from '../../../util/url';
 import { PypiDatasource } from '../../datasource/pypi';
 import { getGoogleAuthHostRule } from '../../datasource/util';
@@ -31,7 +30,7 @@ export function getPythonConstraint(
 ): string | null {
   // Read Python version from `pyproject.toml` first as it could have been updated
   const pyprojectPythonConstraint = Result.parse(
-    pyProjectContent,
+    massageToml(pyProjectContent),
     PoetrySchemaToml.transform(
       ({ packageFileContent }) =>
         packageFileContent.deps.find((dep) => dep.depName === 'python')
@@ -82,7 +81,7 @@ export function getPoetryRequirement(
   }
 
   const { val: pyprojectPoetryConstraint } = Result.parse(
-    pyProjectContent,
+    massageToml(pyProjectContent),
     PoetrySchemaToml.transform(({ poetryRequirement }) => poetryRequirement),
   ).unwrap();
   if (pyprojectPoetryConstraint) {
@@ -98,7 +97,7 @@ export function getPoetryRequirement(
 function getPoetrySources(content: string, fileName: string): PoetrySource[] {
   let pyprojectFile: PoetryFile;
   try {
-    pyprojectFile = parseToml(stripTemplates(content)) as PoetryFile;
+    pyprojectFile = parseToml(massageToml(content)) as PoetryFile;
   } catch (err) {
     logger.debug({ err }, 'Error parsing pyproject.toml file');
     return [];
diff --git a/lib/modules/manager/poetry/extract.spec.ts b/lib/modules/manager/poetry/extract.spec.ts
index cbfa6d4ba770ca83436d6804c0a81cb7b50f4a74..aa0d7da86afc536c2dc96a692f73fd385c6023c6 100644
--- a/lib/modules/manager/poetry/extract.spec.ts
+++ b/lib/modules/manager/poetry/extract.spec.ts
@@ -504,6 +504,7 @@ describe('modules/manager/poetry/extract', () => {
             {# comment #}
             [tool.poetry.dependencies]
             python = "^3.9"
+            {{ foo }} = "{{ bar }}"
             {% if foo %}
             dep1 = "^1.0.0"
             {% endif %}
diff --git a/lib/modules/manager/poetry/extract.ts b/lib/modules/manager/poetry/extract.ts
index 71fb2f0049fe141c6fd08281b45992de2df052f9..f13130e610268a8e125c6001b5eada864441c4f0 100644
--- a/lib/modules/manager/poetry/extract.ts
+++ b/lib/modules/manager/poetry/extract.ts
@@ -7,7 +7,7 @@ import {
   readLocalFile,
 } from '../../../util/fs';
 import { Result } from '../../../util/result';
-import { stripTemplates } from '../../../util/string';
+import { massage as massageToml } from '../../../util/toml';
 import { GithubReleasesDatasource } from '../../datasource/github-releases';
 import type { PackageFileContent } from '../types';
 import { Lockfile, PoetrySchemaToml } from './schema';
@@ -18,7 +18,7 @@ export async function extractPackageFile(
 ): Promise<PackageFileContent | null> {
   logger.trace(`poetry.extractPackageFile(${packageFile})`);
   const { val: res, err } = Result.parse(
-    stripTemplates(content),
+    massageToml(content),
     PoetrySchemaToml.transform(({ packageFileContent }) => packageFileContent),
   ).unwrap();
   if (err) {
diff --git a/lib/util/toml.spec.ts b/lib/util/toml.spec.ts
index b219c42b65915899ed2c0513acfb187674a67083..a589d36dd3dec91345aff611d7206b9b80fb8ea4 100644
--- a/lib/util/toml.spec.ts
+++ b/lib/util/toml.spec.ts
@@ -1,5 +1,5 @@
 import { codeBlock } from 'common-tags';
-import { parse as parseToml } from './toml';
+import { massage, parse as parseToml } from './toml';
 
 describe('util/toml', () => {
   it('works', () => {
@@ -28,4 +28,20 @@ describe('util/toml', () => {
 
     expect(() => parseToml(input)).toThrow(SyntaxError);
   });
+
+  it('handles templates', () => {
+    const input = codeBlock`
+      [tool.poetry]
+      name = "{{ name }}"
+      {# comment #}
+      [tool.poetry.dependencies]
+      python = "^3.9"
+      {{ foo }} = "{{ bar }}"
+      {% if foo %}
+      dep1 = "^1.0.0"
+      {% endif %}
+    `;
+
+    expect(() => parseToml(massage(input))).not.toThrow(SyntaxError);
+  });
 });
diff --git a/lib/util/toml.ts b/lib/util/toml.ts
index 51814334a56de6d61c30139307010837b1171461..dbee015afcbaec7543954a13f15021db05e7983a 100644
--- a/lib/util/toml.ts
+++ b/lib/util/toml.ts
@@ -1,6 +1,12 @@
 import { getStaticTOMLValue, parseTOML } from 'toml-eslint-parser';
+import { regEx } from './regex';
+import { stripTemplates } from './string';
 
 export function parse(input: string): unknown {
   const ast = parseTOML(input);
   return getStaticTOMLValue(ast);
 }
+
+export function massage(input: string): string {
+  return stripTemplates(input.replace(regEx(/^\s*{{.+?}}\s*=.*$/gm), ''));
+}